# Mongoose Schema & Model — MongoDB

Source: https://www.geekswithgeeks.com/en/mongodb/mongo-mongoose-basics

> Add structure on top of MongoDB with Node.js.

## Defining a schema

A **Mongoose schema** declares expected fields and types; `model()` turns it into a class you can use to query.

```javascript
const { Schema, model } = require("mongoose");

const userSchema = new Schema({
  name: String,
  email: String,
  age: Number
});

const User = model("User", userSchema);
```

## Creating & saving a document

Models give you familiar, promise-based methods like `create()` and `.save()`.

```javascript
const user = await User.create({
  name: "Ada Lovelace",
  email: "ada@example.com",
  age: 36
});
```

## Structure on a schema-less DB

MongoDB itself doesn't enforce a schema — Mongoose adds that structure at the application layer, in your Node.js code.
