title: Using the results of one Mongoose query for another one
body: <p>I'm building an app in Node and using Mongoose with CosmosDB. I want to display all of the plots owned by the company with which the logged in user is associated.</p>
  
  <p>I have a user, from Passport.js, whose email I use to query the database in order to return his company. That returns fine.</p>
  
  <p>Where I'm having trouble: once I have his company, I want to run a second query to get all the plots which belong to it. This should be bringing back an array of objects, but it returns an empty array. </p>
  
  <p>Two questions: </p>
  
  <ol>
  <li>How can I make the current code work?</li>
  <li>The current structure is very awkward-how do I make it more elegant?</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>   app.get('/plots',
          requireAuth,
          function(req, res) {
              let company;
              User.find({ email: req.user.email }).lean().exec(function(err, results) {
                  if (err) {
                      console.log(err);
                  }
                  if (!results) {
                      res.send(null);
                      return;
                  } else {
                      company = results[0].company;
                  };
              }).then(
                  PlotCast.find({ owner: company }).lean().exec(function(err, results) {
                      if (err) {
                          console.log('error', err);
                          res.send(err);
                      } else if (!results) {
                          res.send(null);
                      } else {
                          console.log('results', results);
                          res.send(results);
                      }
                  })
              ).catch(function(e) {
                  console.log('error', e);
              });
          }
      )
  </code></pre>