My code is like that:
SiteModel.find( {}, function(docs) { next(null, { data: docs }); } );
but it never returns anything... but if I specify something in the {} then there is one record. so, how to findall?
Now, to get all users list from the mongoose collection you have to call User. find() with an empty object as the first parameter. It will search for all the documents that match with the filter Object. But when you pass an empty filter, it will match with all the documents and will return all documents.
find() function returns an instance of Mongoose's Query class. The Query class represents a raw CRUD operation that you may send to MongoDB. It provides a chainable interface for building up more sophisticated queries.
The value of the $in operator is an array that contains few values. The document will be matched where the value of the breed field matches any one of the values inside the array.
Mongoose | findOne() FunctionThe findOne() function is used to find one document according to the condition. If multiple documents match the condition, then it returns the first document satisfying the condition. Installation of mongoose module: You can visit the link to Install mongoose module.
Try this code to debug:
SiteModel.find({}, function(err, docs) { if (!err) { console.log(docs); process.exit(); } else { throw err; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With