Reputation: 4062
I am trying to update multiple fields of a document:
Game.findByIdAndUpdate(gameId, {
$addToSet: {
players: player.id
},
$addToSet: {
playersInfo: player
}, function(err, model){...}
}
But this query only executes my last $addToSet
Upvotes: 1
Views: 4651
Reputation: 19464
In JavaScript an object cannot have the same key multiple times. So the second overwrites the first.
Try this:
Game.findByIdAndUpdate(gameId, {
$addToSet: {
players: player.id,
playersInfo: player
}, function(err, model){...}
})
Upvotes: 2