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
This commit is contained in:
Owais Ali
2019-03-08 22:51:00 +05:00
committed by Randell Dawson
parent f6d07f37d7
commit 3eab20af32

View File

@ -3,8 +3,22 @@ title: Create a Model
---
## Create a Model
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/apis-and-microservices/mongodb-and-mongoose/create-a-model/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
### Creating Schema
See the [Mongoose docs](https://mongoosejs.com/docs/guide.html) first where is a lot of useful stuff.
When you are building schema you can use either of three options for name validation
```javascript
name: String
name: {type: String}
name: {type: String, required: true} //preferred
```
For array of favoriteFoods here is the validation:
```javascript
favoriteFoods: [{ type: String }]
```
### Creating a Model
Now that we have the schema of our model, we can actually create a model by:
```javascript
var Model = mongoose.model('Model', modelSchema);
```
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->