I have:
Emotion.find (query, "-_id", opts, function (error, e){
if (error) return cb (error, 500);
for (var i=0, len=e.length; i<len; i++){
e[i] = convert (e[i]);
}
cb (null, e);
});
If the function returns 1k documents I have to iterate 1k times.
How can I add a callback that is executed for every document? Something like:
var each = function (e){
return convert (e);
};
Emotion.find (query, "-_id", opts, each, function (error, e){
if (error) return cb (error, 500);
cb (null, e);
});
I basically need to use each() from mongodb: http://mongodb.github.com/node-mongodb-native/api-generated/cursor.html#each
Edit: Perhaps this can be done listening a data event from a stream and pushing the document to an array: