I am stuck on an asynchronous algorithm:
I have an array of mongoose models:
var allRefDatasSchemas = { RefAllotement: mongoose.model('RefAllotement', RefDataSchema), RefModeleConstructeur: mongoose.model('RefModeleConstructeur', RefDataSchema), RefTypeKit: mongoose.model('RefTypeKit', RefDataSchema), RefTypeUtilisation: mongoose.model('RefTypeUtilisation', RefDataSchema), };
I would like to grab all the elements of each collection and put them in an array or something like that. If I do this , the find keyword of this callback does not apply to the current model, so itβs impossible for me to find out which elements of the model belong
var results = {}; for (var model in allRefDatasSchemas) { allRefDatasSchemas[model].find(function(err, data) {
I also tried the async library without success, because I always return to the same problem: it is impossible to find out which model is executing to find the query inside the callback. Also in then if I use promises.
Please help me :) How would you do this?
EDIT model.find calls query.find, query.find calls mquery.find. A callback is called in mquery.find, losing this link at this time: this._collection.find (conds, options, utils.tick (callback)); / EDIT
Etienne
source share