Home > Software engineering >  How to decrement value in mongodb
How to decrement value in mongodb

Time:12-11

  Players.update(Session.get("selected_player"), {$inc: {score: 5}});

I want to drecement the score .

 Players.update(Session.get("selected_player"), {$inc: {score: 5}});

score 5 score 4

decrement by 1

CodePudding user response:

Increment the score by -1 will allow decrementing by 1.

Players.update(Session.get("selected_player"), {$inc: {score: -1}});

Demo @ Mongo Playground

  • Related