title: mongoose : find data by looping on an array of models
body: <p>i'm getting stuck on an asynchronous algorithm :</p>
  
  <p>I've an array of mongoose models :</p>
  
  <pre><code>var allRefDatasSchemas = {
    RefAllotement: mongoose.model('RefAllotement', RefDataSchema),
    RefModeleConstructeur: mongoose.model('RefModeleConstructeur', RefDataSchema),
    RefTypeKit: mongoose.model('RefTypeKit', RefDataSchema),
    RefTypeUtilisation: mongoose.model('RefTypeUtilisation', RefDataSchema),
  };
  </code></pre>
  
  <p>I'd like to grab all items of each collection and put them in an array or something like that.
  If I do that, the <code>this</code> keyword of the <code>find</code> callback doesn't refer to the current model,
  so impossible for me to know which model items belong to</p>
  
  <pre><code>var results = {};
  
  for (var model in allRefDatasSchemas) {
  
    allRefDatasSchemas[model].find(function(err, data) {
  
      // I'd like to do something like that :
      // but this.modelName is null, because it isn't the model
      // on which the find is done.
      results[this.modelName] = data;
  
      // if I use "model" variable, it doesn't work, because asynchronous callback
  
    });
  
  }
  </code></pre>
  
  <p>I've also tried <a href="https://github.com/caolan/async#parallel" rel="nofollow">async</a> library without success, because I always return to the same issue : impossible to know which model execute the find query inside the callback.
  Idem in a <code>then</code> if I use promises.</p>
  
  <p>Please help me :) How would you do that ?</p>
  
  <p>EDIT
  model.find calls query.find, query.find calls mquery.find. In mquery.find, callback is called, by lost the this reference a that time : this._collection.find(conds, options, utils.tick(callback));
  /EDIT</p>