title: Not able to access result returned from mongoDb outside query
body: <p>I am working with node.js using express and mongoDb.
  I am trying to retrieve data from database "local" and collection "borrower" and pushing it into an empty array <code>collectionOne</code>. It is rendering this array on the view page. 
  I want to use  _id pushed in an array <code>b_ids</code> from this output to make a call to <code>company_details</code> collection under same router .
  The issue I am facing here is I am not getting any value in array <code>b_ids</code> when trying to access it under call to <code>company_details</code> collection.</p>
  
  <p>The code is as below:</p>
  
  <pre><code>var collectionOne = [];
  var collectionTwo = [];
  var b_ids = [];
  
  router.get('/fetch',function(req, res, next){
   MongoClient.connect('mongodb://localhost:27017/local', function(err, db){
      var collection = db.collection('borrower');
  
      db.collection("borrower", function(err, collection) {
          collection.find().toArray(function(err, result) {
                                              if (err) {
                                                throw err;
                                              } else {
                                                  //console.log(result[0].first_name);
                                                for (i=0; i&lt;result.length; i++) {
                                                  collectionOne[i] = result[i];
                                                  b_ids[i] = result[i]._id;
                                                }
                                              }
                                      });
  
          db.collection("company_details", function(err, collection){
              console.log(b_ids);
              collection.find({borrower_id : {$in :b_ids}}).toArray(function(err, result){
                  if (err) {
                    throw err;
                  } else {
                    for (i=0; i&lt;result.length; i++) {
                      collectionTwo[i] = result[i];
                    }
                  }
              });
          });
          res.render('index',{data : collectionOne , data1 : collectionTwo});
      }); 
   });
  });
  </code></pre>
  
  <p>Please suggest me how can I access the b_ids array here. Thanks in advance :)</p>