I have the following Meteor.js collection:
Game: {
_id: 1,
rounds: {
round: {
number: 1,
players: {
player: {
_id: someId,
cardSelection: someCard
}
player: {
_id: someId2,
cardSelection: someCard2
}
}
}
}
There are some other fields in the collection but these are the important ones. I'm trying to update a player's selection when they click a card. I'm unsure how to do this in MongoDB/Meteor.
So far, I've tried: var currentRound = Games.findOne(gameId).rounds.length;
Games.update({_id: gameId,
"rounds.round": currentRound,
"rounds.round.$.players": playerId
},
{$set:
{"rounds.$.players.$": {id: playerId, selection: selection}}
}
);
The problem is that when calling the update, I don't know the rounds position (well I do, its the last round, but the round number changes), and I don't know the player's position inside the Players object inside the Round object.
Any help?
Gamedocument. Shouldroundsandplayersboth be Arrays?