Files
chayawit cf8a79c0af Replace stub page with new hints (#34799)
* Replace stub page

* Update index.md
2019-03-08 12:16:27 -08:00

1.0 KiB

title
title
Create a Model

There are 3 things to do in this challenge. You can click each item to see the code.

Assign Mongoose Schema to a variable. This is not necessary but will make your code easier to read.
const Schema = mongoose.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
Create Person schema.
const personSchema = new Schema({
  name: { type: String, required: true },
  age: Number,
  favoriteFoods:   [String]
});

Note: If you choose to skip the first step, you have to use mongoose.Schema instead of Schema.

Create Person model from the schema.
const Person = mongoose.model('Person', personSchema);