these days i'm trying to learn more about mongoose to implement it in my project ,while going through the doc , i saw both Model and Query, both have many methods in common ,my question is what is the difference between them for example
Model.findOne()vs Query.prototype.findOne(), and thank you in advance.
Model.findOne() is the actual way to finding single document from database using findOne() query
whereas Query.prototype.findOne() means prototype of findOne Query
as per documentation : you can pass your filter, projection, options objects and callback function to your query
example :
Kitten.where({ color: 'white' }).findOne(function (err, kitten) {
if (err) return handleError(err);
if (kitten) {
// doc may be null if no document matched
}
});
mongoose have displayed prototypes of all Query you can use to your Model , means what you can pass to your Query while finding documents.
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