Repolode
Automattic

Automattic/mongoose

MongoDB object modeling for Node.js, providing schemas, models, validation, and query helpers for async applications.

Stars
27,460
Forks
4,074
Open issues
182
Last commit
4 hours ago

What is it?

Mongoose is an object data modeling (ODM) library for MongoDB, built for Node.js applications that run in an asynchronous environment. It lets developers describe the shape of their documents with schemas, then work with them as model instances that can be validated, saved, queried, and updated.

A schema defines field types, defaults, validators (sync and async), getters and setters, indexes, middleware hooks, instance methods, static methods, and plugins. Models built from schemas expose query methods such as find, findOne, and findById, and documents support embedded subdocuments and population for cross-collection references.

Mongoose is built on the official MongoDB Node.js driver and runs on Node.js, with alpha Deno support. It also supports multiple connections via createConnection. Mongoose Studio, a companion browser-based MongoDB GUI that works with existing Mongoose models, is also available.

Key features

  • 01Define document schemas with types, defaults, and validators
  • 02Query, create, update, and delete documents through model methods
  • 03Embedded subdocuments and populate for cross-collection references
  • 04Middleware hooks, instance methods, static methods, and plugins
  • 05Built on the official MongoDB Node.js driver, with support for multiple connections

Use cases

  • Adding a structured data layer to a Node.js or Express backend that uses MongoDB
  • Enforcing validation and defaults on documents before they are written to the database
  • Sharing reusable schema logic across models with plugins

Quick start

  1. 1

    Install Node.js and MongoDB first

  2. 2

    Install the mongoose package with npm

    npm install mongoose
  3. 3

    Connect to your MongoDB database in your code

    await mongoose.connect('mongodb://127.0.0.1/my_database');

Things to know

  • Requires a separately installed MongoDB server to work with.

Topics

FAQ

What is mongoose?
MongoDB object modeling for Node.js, providing schemas, models, validation, and query helpers for async applications. Mongoose is an object data modeling (ODM) library for MongoDB, built for Node.js applications that run in an asynchronous environment. It lets developers describe the shape of their documents with schemas, then work with them as model instances that can be validated, saved, queried, and updated.
Is mongoose free to use? What license does it have?
mongoose is open source under the MIT license. Check the license terms before using it in commercial products.
Is mongoose still maintained?
Actively maintained. The last commit to mongoose was on Oct 21, 2026.
What can I use mongoose for?
Adding a structured data layer to a Node.js or Express backend that uses MongoDB Enforcing validation and defaults on documents before they are written to the database Sharing reusable schema logic across models with plugins
How do I install mongoose?
Install Node.js and MongoDB first Install the mongoose package with npm: npm install mongoose Connect to your MongoDB database in your code: await mongoose.connect('mongodb://127.0.0.1/my_database');
Where can I get mongoose?
The source code and installation instructions are on GitHub: https://github.com/Automattic/mongoose

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects