title: Strange result when nesting query of two different collections
body: <p>I have a need to check two separate collections in Mongo to see if a phone number exists.</p>
  
  <p>I first created a global variable called 'ownerId'</p>
  
  <p>I then look in one collection call 'Profile'. If the email value I pass exists in the 'emails' array of a document in that collection, I fill the 'ownerId' variable I created with a value in that document called 'owner_id'.</p>
  
  <p>I then look in another collection called 'User', which has a single email field. If the email value I pass exists in a document in that collection, I fill the 'ownerId' variable I created with the '_id' of that document.</p>
  
  <p>I have my queries nested in a couple 'then()' statements.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>            Profile.findOne({'emails.email_address':req.body.invited_email}, function(err, result){
  
                  if(result)
                      ownerId = result.owner_id;
  
              }).then(function(){
                  User.findOne({'email':req.body.invited_email}, function(err, result2){
  
                      if(ownerId !== null)
                          ownerId = result2._id;
                  })
              }).then(function(){
  
                console.log(' --------------- THIS IS AN EXISTING EMAIL OWNER ID: ' + ownerId);
  
              })
  </code></pre>
  
  <p>The result is not as I expect.</p>
  
  <p>If the 'Profile' query is true and finds a match, then it will console log the ownerId with a value.</p>
  
  <p>If the second 'User' query is true, but there is not match for the 'Profile' it will console log 'null'. I expect it to console log the _id value of the User result.</p>
  
  <p>Can anyone see the error in my logic?</p>