Answer the question
In order to leave comments, you need to log in
How to make links between collections?
There are 3 models:
League - name
Season - name Match -
homeTeamName, awayTeamName, score?, date
It is necessary to make it so that when choosing a league there is a search by seasons, when choosing a season, search by matches. Please tell me how to do it correctly and how to link it so that when creating a match there is a connection for the season and the season is already in the league?
Answer the question
In order to leave comments, you need to log in
Create in the League model
seasonId: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Season' }]
matchId: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Match' }]
leagueModel.create(leagueData)
seasonModel.create(seasonData)
leagueModel.updateOne({ _id: leagueId }, { $push: { seasonId: inputSeasonId } })
leagueModel.findById(leagueId).populate('seasonId')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question