Skip to content

Intro to Mongoose

Mongoose is the industry-standard ODM for Node.js. It allows us to define a Schema, which acts as a blueprint for our data.

It manages relationships between data, provides schema validation, and is used to translate between objects in code and the representation of those objects in MongoDB.

  • Flexible Evolution: A major perk of Mongoose is that our Schema can change over time without needing a “migration”. If we add a field today, existing documents stay as-is, and new ones follow the new rules.
  • The Model: Once a Schema is defined, we pass it into mongoose.model(). This creates a JavaScript constructor that allows us to query, save, and delete documents with ease.
T.A. Watts

Don’t confuse the Schema (the plan) with the Model (the tool). We build the tool from the plan.

Want to see the official specs? Check out the MongoDB homepage.

Visit Mongoose Official Website


📘 What is Mongoose? (PNG)

📘 Intro to Mongoose (PNG)

MongoDB & Mongoose Intro - Demo Repo - Completed Minimal Server

Let’s get our hands dirty and set up the application structure.