Hi there, I have two tasks to do:
1. Mongo Call ---> simple find with query
2. Searching in the result of Mongo find with forEach and making another request to different collection..
3. res.send changes which have been done in forEach loop.
For now it looks like that:
db.collection.find().sort({ "rank": order }).skip(pagenumber).limit(5, function (err, result) {
currData = result;
});
find(currData);
res.send(currData);
and find is a function() like :
function find(db) {
db.forEach(function (prevResult) {
db.collectionOther.find({ MID: commId }, function (error, result) {
result.forEach(function (r) {
some calculations;
if (condition) {
prevResult= Calculations;
}
});
});
});
I tired to do it whit process.nextTick but failed. Could someone help mi to make the calls be done after each other and not at the same time?