UPDATE - Solution:
I was for looping instead should have used MongoDBs $in
feature - details here
I have the following Q.all block:
Q.all([
getFirstBlock(),
getSecondBlock(),
])
.then(function(){
getSecondBlockProcessed();
})
.then(function(){
res.json(completeArray);
});
The problem I have is when I go into the final then
block I notice that the function getSecondBlockProcessed
has not been completed.
Everything in the first Q.all
is done.
Why isn't that promise getting resolved?
And the method in question looks like:
var getSecondBlockProcessed = function() {
return Q.promise(function(resolve, reject) {
for (var i=0; i<mostInRegion.length; i++){
Person.find(
{_id: mostInRegion[i]['_id']},
{question:1, country: 1},
function(err, found) {
mostInRegion2.push(found);
})
}
resolve();
});
}
Any help would be appreciated/what have i overlooked?
Thanks