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)
Parameter
Description
name
Model name, this will be the name of the JSON file and will be used to identify the database
The schema of the model.
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
type
required
default
(optional)
Receives a default value if none is passed when creating a document, this default value must follow the type defined
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