title: Return data from mongoDB nested queries
body: <p>What is the method to return data from nested queries. </p>
  
  <p>Im merging multiple function calls into one single module , 
  I have the following code</p>
  
  <pre><code>  retrieveStudentSessions: function(req, res, callback){
       MongoClient.connect(config.mongoPath+config.dbName, function(err, db) {
         if(err){
           return callback(new Error("Unable to Connect to DB"));
         }
        var collection        = db.collection(config.userList);
        var sessionCollection = db.collection(config.session);
        var templateCollection = db.collection(config.template);
        var tempSession  = {session:[], templates:[]};
  
        //Obtain UserID
        collection.find({'email' : req.user['_json'].email}).nextObject(function(err, doc) {
            if(err){
                  return callback(new Error("Error finding user in DB"));
            } 
            //Search Session collection for userID
              sessionCollection.find({ $or : [{'studentsB' : doc['userid']},{'studentsA' : doc['userid']}]}).each(function(err, doc) {
                if(err){
                    return callback(new Error("Error finding user in DB"));
                }  
                    //Update JSON
                    tempSession.session.push(doc);
                    //Query for Template Title using Template ID from Session Collection
                    templateCollection.find({'_id' : doc['templateId']}).nextObject(function(err, doc){
                      if(err){
                            return callback(new Error("Error finding user in DB"));
                      } 
                      //Update JSON
                      tempSession.templates.push(doc);
                    });
              });
          return callback(null, tempSession);
        });
      });
    }
  </code></pre>
  
  <p>Caller Function</p>
  
  <pre><code>dbCall.retrieveStudentSessions(req, res, function(err, result){
                  if(err){
                      console.log(err);
                      return;
                  }
                  console.log(result);
              });
  </code></pre>
  
  <p>Above code returns error <code>undefined is not a function</code> when i try to return variable <code>tempSession</code>. The same works fine with single queries . Is there any specific method of return, when it comes to nested queries? </p>