fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles * fix: added 3 dashes line before prob expl * fix: added 3 dashes line before hints * fix: added 3 dashes line before solutions
This commit is contained in:
@@ -2,40 +2,47 @@
|
||||
title: Create a Model
|
||||
---
|
||||
|
||||
# Create a Model
|
||||
|
||||
|
||||
---
|
||||
## Solutions
|
||||
|
||||
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
||||
|
||||
There are 3 things to do in this challenge. You can click each item to see the code.
|
||||
|
||||
<details>
|
||||
<summary>Assign Mongoose Schema to a variable. This is not necessary but will make your code easier to read.</summary>
|
||||
**Assign Mongoose Schema to a variable**
|
||||
This is not necessary but will make your code easier to read.
|
||||
|
||||
```javascript
|
||||
const Schema = mongoose.Schema;
|
||||
```
|
||||
</details>
|
||||
|
||||
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
|
||||
```js
|
||||
```
|
||||
|
||||
name: String
|
||||
name: {type: String}
|
||||
name: {type: String, required: true} //preferred
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Create Person schema.</summary>
|
||||
**Create Person schema.**
|
||||
|
||||
```javascript
|
||||
const personSchema = new Schema({
|
||||
name: { type: String, required: true },
|
||||
age: Number,
|
||||
favoriteFoods: [String]
|
||||
favoriteFoods: [String]
|
||||
});
|
||||
```
|
||||
**Note**: If you choose to skip the first step, you have to use `mongoose.Schema` instead of `Schema`.
|
||||
</details>
|
||||
<details>
|
||||
<summary>Create Person model from the schema.</summary>
|
||||
|
||||
**Create Person model from the schema.**
|
||||
|
||||
```javascript
|
||||
const Person = mongoose.model('Person', personSchema);
|
||||
const Person = mongoose.model("Person", personSchema);
|
||||
```
|
||||
</details>
|
||||
|
||||
|
Reference in New Issue
Block a user