Files
Owais Ali 3eab20af32 add guide of certificate/api/create a model (#29472)
* add guide of certificate/api/create a model

* Add syntax highlighting

* Update index.md syntax highlighting
2019-03-08 09:51:00 -08:00

757 B

title
title
Create a Model

Create a Model

Creating Schema

See the Mongoose docs first where is a lot of useful stuff. When you are building schema you can use either of three options for name validation

name: String
name: {type: String}
name: {type: String, required: true} //preferred

For array of favoriteFoods here is the validation:

favoriteFoods: [{ type: String }]

Creating a Model

Now that we have the schema of our model, we can actually create a model by:

var Model  = mongoose.model('Model', modelSchema);