title: MongoDB nested collection query of same collection
body: <p>How do you do a nested query when you need the results of the same collection in the next query?</p>
  
  <pre><code>var mongo = require('../config/mongo');
  
  var mongoDB = mongo.db;
  ...
  
  exports.myFunction = function(req, res) {
  
  ...
  ...
  // e.g. myArray = ['a','b','c'];
  
  mongoDB.collection('MyCollection', function(err, collection) {
      collection.find({ $or: [{ 'source': {$in: myArray} },{ 'target': {$in: myArray} }]}, { "someVar": 0}).toArray(function(err, firstResults) {
  
              var allResults = [];
              for (var i = 0; i &lt; firstResults.length; i++) {
                  allResults[firstResults[i].source]=1;
                  allResults[firstResults[i].target]=1;
              };
  
              var secondResults = Object.keys(allResults);
  
              mongoDB.collection('MyCollection', function(err, collection) {
                  collection.find({ $or: [{ 'source': {$in: secondResults} },{ 'target': {$in: secondResults} }]}, { "someVar": 0}).toArray(function(err, items) {
                      res.send(items);
                  });
              });
  
  
      });
  });
  </code></pre>
  
  <p>But it doesn't like that I am calling the same collection 'MyCollection' twice. I'm trying to get any document whose source or target involves secondResults. </p>