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_2—will store the information of the two teams playing. The score of the match. That's all we need for our model.