Mongoose find with reference to object
I have a find inside a loop:
for(var idx in items){
var item = items[idx];
Model.find({'_id': item.id}, function(err, matches){
console.log(item); // Points to the last item in items instead of
// expected item, since find is asynchronous
});
}
As you see, since find is asynchronous I can't get a solid reference to
the item var.
I could go ahead and manually look for it again in the items array by the
matched object inside the callback but that just doesn't seems like an
effective approach.
If there would be any way to "attach" an object to the call so I could get
it back with the callback that would be awesome.
Any ideas ?
No comments:
Post a Comment