Mongoose ODM v8. 16. 0 Mongoose provides a straight-forward, schema-based solution to model your application data It includes built-in type casting, validation, query building, business logic hooks and more, out of the box
Mongoose v8. 16. 0: Getting Started That's the end of our quick start We created a schema, added a custom document method, saved and queried kittens in MongoDB using Mongoose Head over to the guide, or API docs for more
Mongoose v8. 16. 0: Schemas If you haven't yet done so, please take a minute to read the quickstart to get an idea of how Mongoose works If you are migrating from 7 x to 8 x please take a moment to read the migration guide Defining your schema; Creating a model; Ids; Instance methods; Statics; Query Helpers; Indexes; Virtuals; Aliases; Options
Mongoose v8. 16. 0: Connecting to MongoDB You can connect to MongoDB with the mongoose connect() method mongoose connect ('mongodb: 127 0 0 1:27017 myapp'); This is the minimum needed to connect the myapp database running locally on the default port (27017) For local MongoDB databases, we recommend using 127 0 0 1 instead of localhost
Mongoose v8. 16. 0: Documents Documents are casted and validated before they are saved Mongoose first casts values to the specified type and then validates them Internally, Mongoose calls the document's validate() method before saving
Mongoose v8. 16. 0: Models In Mongoose, you should define a separate Model for each of your Views You can also create a View using createCollection() The following example shows how you can create a new RedactedUser View on a User Model that hides potentially sensitive information, like name and email
Mongoose v8. 15. 1: Field Level Encryption Mongoose supports the declaration of encrypted schemas - schemas that, when connected to a model, utilize MongoDB's Client Side Field Level Encryption or Queryable Encryption under the hood Mongoose automatically generates either an encryptedFieldsMap or a schemaMap when instantiating a MongoClient and encrypts fields on write and decrypts
Mongoose v8. 16. 0: SchemaTypes You can think of a Mongoose schema as the configuration object for a Mongoose model A SchemaType is then a configuration object for an individual property A SchemaType says what type a given path should have, whether it has any getters setters, and what values are valid for that path