Defining schemas

To store information in our database we need to create a model, this model is created based on a initial schema definition. This schema definition contains the attributes and datatypes of the information we want to store. Let's define the schema for our collections of teams. In the same mongoose-connection.js file, add the following code:

...
const TeamSchema = new mongoose.Schema({
name: String,
ranking: Number,
captain: String,
trainer: String,
confederation: String
})

As you can see, defining schemas is straightforward. We use the mongoose.Schema object and define the fields we want for our schema as a JSON object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset