How to query two collection in mongoose on nodeJs?

hi am new to nodeJs i have to query a table from the result of the query, i have to query another table. i tried the code as follows but it returns only null.

 action(function getpositions(req){
 var namearray = [];
 NHLPlayerStatsDaily.find ({"created_at": {$gt: new Date(y+"-"+m+"-"+d)}}, function(err,position){
    if(!err)
    { 
    for (i=0;i< position.length; i++)
    {  
        var obj = JSON.stringify(position[i]);
        var pos = JSON.parse(obj);

        var p = pos["player_stats_daily"]["content"]["team_sport_content"]["league_content"]["season_content"]["team_content"]["team"]["id"]
        NHLTeam.find({"sdi_team_id": p}, "first_name nick_name short_name sport_id", function(err, team){
                 if (!err){
                    var obj = JSON.stringify(team);
                    var pos = JSON.parse(obj);
                    namearray.push(team)
                   }
            })
        }
      return send(namearray);
    }
      })
       })

if i just push "p" it shows the result and when am query "NHLTeam" in separate function it also shows the result. when querying a collection with in collection it return null. how to query a collection within a collection in mongoose. thanks in advance.

This is not a query problem, it is callback issue. The send(namearray) is called before any of the NHLTeam queries in the loop are completed (remember the result of these queries is passed to callback asynchronously).

What you can do is this (basically tracking when all callbacks are completed):

NHLPlayerStatsDaily.find ({"created_at": {$gt: new Date(y+"-"+m+"-"+d)}}, function(err,position){
  if(!err)
  { 
    var total = position.length;

    for (i=0;i< position.length; i++)
    {  
      var obj = JSON.stringify(position[i]);
      var pos = JSON.parse(obj);

      var p = pos["player_stats_daily"]["content"]["team_sport_content"]["league_content"]["season_content"]["team_content"]["team"]["id"]
      NHLTeam.find({"sdi_team_id": p}, "first_name nick_name short_name sport_id", function(err, team){
        total--;
        if (!err){
          var obj = JSON.stringify(team);
          var pos = JSON.parse(obj);
          namearray.push(team);
        }
        if(total == 0)
            send(namearray);
      })
    }

  }
})