I feel like I should be beyond these type of issues by now, but I have a method where I’m updating a collection with $inc
, but when I call the method, the $addToSet
is completed, but my number is never incremented. I get no errors in the server or client console, and a success message back.
return Games.update({ _id: gameId },
{ $addToSet: { players: { name: teamName, points: 0, questionsCorrect: 0 }}},
{ $inc: { numberOfPlayers: 1 }
});
is the update I’m calling. Here is my initial insert statement from a different method completely.
return Games.insert({
gameType: gameType,
gameName: gameName,
questionType: qType,
questionDifficulty: qDiff,
questionCategory: qCat,
gameCode: gameCode,
gameStatus: '',
active: 'Yes',
numberOfPlayers: 0,
addedOn: new Date(),
addedBy: Meteor.users.findOne(this.userId).username,
});
And my results from the insert, followed by the update later are below (NOTE: I have some other updates that happen before this one is called, so some extra data is here).
{
"_id" : "jSjpTh9PG8ie3x4fc",
"gameType" : "allA",
"gameName" : "Campout1",
"questionType" : "mixed",
"questionDifficulty" : "mixed",
"questionCategory" : [
"Family"
],
"gameCode" : "I5I2g0",
"gameStatus" : "Waiting",
"active" : "Yes",
"numberOfPlayers" : 0,
"addedOn" : ISODate("2017-04-22T23:20:01.774Z"),
"addedBy" : "bmcgonag",
"numberofQuestions" : [
11
],
"qandAs" : [
[
"bjxvLEYWyXKYPAGvu",
"zFZ6fCLonnRFPTpFv",
"PSJv7Tb55cqMK3Gzj",
"yAjgEGzfvkSkEywEd",
"4iTXvxRLr5CL4cTMR",
"rAtcCRCJsmfYh6S72",
"7ero5gmArdZANLun9",
"3tmyTA2G6kFYZ5JFc",
"pzLH45W34GQtJ4bHc",
"T2yRKJu67vdSvmN26",
"fm2ZQazXfzg8ZdWFf"
]
],
"players" : [
{
"name" : "lopezb29",
"points" : 0,
"questionsCorrect" : 0
}
]
}
As you can see, I’ve successfully added the player, but my number of players did not increment up.
I’m sure I’ve messed up somewhere, but not sure where, and as always any help is greatly appreciated.