Mongoose v6.6.7: Mongoose Tutorials: Query Casting
The first parameter to Model.find(), Query#find(), Model.findOne(), etc. is called filter. In older content this parameter is sometimes called query or conditions. For example: When you execute the query using Query#exec() or Query#then(), Mongoose casts the filter to match your schema. If Mongoose fails to cast the filter to your schema, your query will throw a CastError. By default, Mongoose does not cast filter properties that aren't in your schema. You can configure this behavior using the strictQuery option for schemas. This option is analogous to the strict option. Setting strictQuery to true removes non-schema properties from the filter: To make Mongoose throw an error if your filter has a property that isn't in the schema, set strictQuery to 'throw': Because of schemas, Mongoose knows what types fields should be, so it can provide some neat syntactic sugar. For example, if you forget to put $in on a non-array field, Mongoose will add $in for you.
Query Casting The first parameter to Model.find() , Query#find() , Model.findOne() , etc. is called filter . In older content this parameter is sometimes called query or conditions . For example: const query = Character . find ({ name : 'Jean-Luc Picard' }); query. getFilter (); // `{ name: 'Jean-Luc Picard' }` // Subsequent chained calls merge new properties into the filter query. find ({ age : { $gt : 50 } }); query. getFilter (); // `{ name: 'Jean-Luc Picard', age: { $gt: 50 } }` When you execute the query using Query#exec() or Query#then() , Mongoose casts the filter to match your schema.
related reading
- SchemaTypes - Mongoose v9.8.0mongoosejs.com
- Queries - Mongoose v9.8.0mongoosejs.com
- mongo/src/mongo/db/query/README.md at master · mongodb/mongogithub.com
- Using TypeScript with Mongoose - Mongoose v9.8.0mongoosejs.com
- Queries | Isar Databaseisar.dev
- An Introduction to Mongoose Arrays - Mastering JSmasteringjs.io
- Welcome to the MongoDB Docs - MongoDB Documentation - MongoDB Docsmongodb.com
- GitHub - redis/redis-om-node: Object mapping, and more, for Redis and Node.js. Written in TypeScript.github.com
- Welcome to the MongoDB Docs - MongoDB Documentation - MongoDB Docsmongodb.com
- Project Cambria: Translate your data with lensesinkandswitch.com
- Intro | Zodzod.dev
- SQL Query Builder for Javascriptknexjs.org