Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Creating a Model | Section
Working with MongoDB in Express Applications

bookCreating a Model

Свайпніть щоб показати меню

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.

question mark

What is the purpose of a schema in Mongoose?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 6

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 6
some-alt