Creating a Model
Sveip for å vise menyen
In Mongoose, a model defines how your data is structured.
To create a model, you first define a schema. A schema describes the fields and their types.
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
name: String,
age: Number
});
Then you create a model based on that schema:
const User = mongoose.model('User', userSchema);
The model is used to interact with the database. It allows you to create, read, update, and delete documents.
For example, each document created with this model will follow the defined structure.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 1. Kapittel 6
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Seksjon 1. Kapittel 6