Currently, I am attempting to modify a collection by adding elements to an existing array within the collection.
Below is the function I am trying to execute for updating:
Games.update({ _id: game._id }, {
$push: { players: { name: playerName } },
});
Upon running this function, the following error is displayed in the console:
update failed: MongoError: Cannot update 'players' and 'players' at the same time
Here are the relevant schemas being utilized:
Player = new SimpleSchema({
name: {
type: String,
label: 'name',
max: 50,
},
});
Schemas.Game = new SimpleSchema({
...
players: {
type: [Player],
label: 'Players',
autoValue: function () {
return [];
},
},
});
Currently, I am using the autoValue
for the players
array to initialize it when a new game is created. Is this initialization causing issues when adding the first player?
Any assistance on this matter would be greatly appreciated.