[Solved] "cursor.toArray is not a function""collection.find() accepts at most two arguments""unhandled promise rejections are deprecated" while using .find() - Mongoose
Article
Ab Siddik
The current version of mongoose will raise the error mentioned if you follow the steps laid out for Model.find()
. No issues for Model.findOne()
though. .find()
method from model returns Query object not Cursor. To execute query, use .exec()
method. Also all async methods should be handled with callbacks.
var apple = Fruit.find( { } , { prop1: 1, prop2: 1, _id: 1 } )
.exec(function(err, fruitsArray){
....
});
Hopefully its can help to you to fix your problem. If you face another issue, you could feel free to contact with us.