meteor

How to decrement like $dec?


In the Meteor leaderboard example there is this line:

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

How can I gracefully decrement the same field? Sadly, there is no $dec.


Solution

  • MongoDB allows you to increment by negative values:

    $inc: {score: -1}