flâneur — a map of the web's best reading

Mongoose v6.6.7: Queries

mongoosejs.com · 1,441 words · saved by 1 readers

Mongoose models provide several static helper functions for CRUD operations. Each of these functions returns a mongoose Query object. A mongoose query can be executed in one of two ways. First, if you pass in a callback function, Mongoose will execute the query asynchronously and pass the results to the callback. A query also has a .then() function, and thus can be used as a promise. When executing a query with a callback function, you specify your query as a JSON document. The JSON document's syntax is the same as the MongoDB shell. Mongoose executed the query and passed the results to callback. All callbacks in Mongoose use the pattern: callback(error, result). If an error occurs executing the query, the error parameter will contain an error document, and result will be null. If the query is successful, the error parameter will be null, and the result will be populated with the results of the query. Anywhere a callback is passed to a query in Mongoose, the callback follows the patter

Queries Mongoose models provide several static helper functions for CRUD operations . Each of these functions returns a mongoose Query object . Model.deleteMany() Model.deleteOne() Model.find() Model.findById() Model.findByIdAndDelete() Model.findByIdAndRemove() Model.findByIdAndUpdate() Model.findOne() Model.findOneAndDelete() Model.findOneAndReplace() Model.findOneAndUpdate() Model.replaceOne() Model.updateMany() Model.updateOne() Mongoose queries can be executed by using await , or by using .then() to handle the promise returned by the query. Executing Queries are Not Promises References to

Explore this link on the map →

related reading