<commit_before>---
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>.

<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds  -->
<commit_msg>add guide of certificate/api/create a model (#29472)<commit_after>---
title: Create a Model
---
## Create a Model

### 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  -->

{'fraction_non_alphanumeric': 0.1275121275121275, 'fraction_numerical': 0.003465003465003465, 'mean_word_length': 4.575289575289576, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1378921', 'n_tokens_mistral': 444, 'n_tokens_neox': 425, 'n_words': 160}