Creating the Match schema

Create the match.js file in the src/models folder. Then, add the following code:

const mongoose = require('mongoose')

const MatchSchema = new mongoose.Schema({
team_1: {
type: String,
min: 3,
max: 100,
required: true
},
team_2: {
type: String,
min: 3,
max: 100,
required: true
},
score: {
team_1: Number,
team_2: Number
}
})

module.exports = mongoose.model('match', MatchSchema)

We have defined three attributes, the first two—team_1 and team_2will store the information of the two teams playing. The score of the match. That's all we need for our model.

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

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