I try to filter an array according to the result of a mongoose query. The standard filter function expect the callback to return true or false. My trouble is that this informati
Use the filter function from the async
library instead.
UPDATE
You're pretty close in your attempt, you just need to provide the result to the callback instead of returning it:
async.filter(myArray, function(elem, callback){
MyCollection.findOne({_id : elem}, function(err, doc) {
callback(err == null && doc != null);
});
},
function(results){
// results is myArray filtered to just the elements where findOne found a doc
// with a matching _id.
});