Schema
Importing
Schema is basically a model to be followed and also a separate database.
It receives two parameters, the first is the name of the model and the second is the standard object of the model, which will be a basis for each document inserted in it.
Schema(model, schema)
Model base
This is where the magic happens, the base model will do the job of typing documents and maintaining a pattern between them, nothing escapes the base model.
Each property of the base model can receive the following properties
The base model must always have a property called _id
of type String
or Number
, since searches in the database will be done from _id
Schema
Example
In this example I will create the model of a user, which must have a _id
, username
that will be required, age
that by default it will be 15 and cats
that by default will come with a registered cat
Last updated
Was this helpful?