Mongoose is a popular MongoDB object modeling tool (ODM) for Node.js and Deno, designed for asynchronous environments. It provides a schema-based solution to model application data, offering powerful validation, querying, and middleware capabilities. The current stable version is 9.4.1, with frequent patch and minor releases addressing bug fixes and new features.
npm install mongooseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to connect to a MongoDB database, define a simple Mongoose schema and model, create a new document, save it, and then query for it.
Upgrade your Node.js environment to version 20.19.0 or newer.
Refer to the official migration guide for Mongoose 9.0 at `https://mongoosejs.com/docs/migrating_to_9.html`.
Replace calls to `document.getChanges()` with `document.$getChanges()`.
Ensure all options passed to Mongoose methods are valid objects or primitive values, not `null` or `undefined`.
Review your `setDefaultsOnInsert` logic for upserts and adjust if you expected setters to run on default values, as this behavior is now off by default again.
Ensure your MongoDB instance is running and accessible at the specified connection URI (e.g., `mongodb://127.0.0.1:27017/`).
Provide values for all required fields as defined in your Mongoose Schema before saving the document. Check other validation rules like `minlength`, `maxlength`, `enum`, etc.
Ensure that the value you are providing for `_id` or any other `ObjectId` field is a valid 24-character hexadecimal string or an actual `ObjectId` instance.
Provide a valid options object (even an empty one `{}`) or omit the options parameter entirely if no options are needed.Install the package using `npm install mongoose`, `yarn add mongoose`, or `pnpm add mongoose`. If using ESM, ensure your `package.json` is configured correctly (e.g., `type: module`).
No dependency data recorded yet.