From 3eab20af322c42d1ef1fa0e8a5dd73f6f9d16cc3 Mon Sep 17 00:00:00 2001 From: Owais Ali Date: Fri, 8 Mar 2019 22:51:00 +0500 Subject: [PATCH] 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 --- .../create-a-model/index.md | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/create-a-model/index.md b/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/create-a-model/index.md index a88c17f478..6310d7cb7b 100644 --- a/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/create-a-model/index.md +++ b/guide/english/certifications/apis-and-microservices/mongodb-and-mongoose/create-a-model/index.md @@ -3,8 +3,22 @@ title: Create a Model --- ## Create a Model -This is a stub. Help our community expand it. - -This quick style guide will help ensure your pull request gets accepted. +### 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); +```