Mongoose v6.6.7: Queries
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
related reading
- mongo/src/mongo/db/query/README.md at master · mongodb/mongogithub.com
- Welcome to the MongoDB Docs - MongoDB Documentation - MongoDB Docsmongodb.com
- Query Casting - Mongoose v9.8.0mongoosejs.com
- Welcome to the MongoDB Docs - MongoDB Documentation - MongoDB Docsmongodb.com
- An Introduction to Mongoose Arrays - Mastering JSmasteringjs.io
- SQL Query Builder for Javascriptknexjs.org
- The vector database to build knowledgeable AI | Pineconepinecone.io
- Queries | Isar Databaseisar.dev
- SQL vs NoSQL in 8 Examples | Towards Data Sciencetowardsdatascience.com
- Using TypeScript with Mongoose - Mongoose v9.8.0mongoosejs.com
- GitHub - redis/redis-om-node: Object mapping, and more, for Redis and Node.js. Written in TypeScript.github.com
- SchemaTypes - Mongoose v9.8.0mongoosejs.com