How to get a callback on MongoDB collection.find() in node.js

Published on Author Code Father

If you want your callback to provide results as an array of documents, change the find to:

collection.find({'_id':o_id}, function(err, cursor){
    cursor.toArray(callback);
    db.close();}
);

Note that your function’s callback still needs to provide an err parameter so that the caller knows whether the query worked or not.

Comments

comments