How to decree like $ dec?

The Meteor leaderboard example has this line:

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

      

How can I gracefully shrink one field? Sorry, no $ dec.

+15


source to share


3 answers


Increase by -1?



$inc: {score: -1}

      

+38


source


From MongoDB docs (linked to Meteor docs): The $ inc update operator takes both positive and negative values. A negative value effectively decreases the specified field.



http://docs.mongodb.org/manual/reference/operator/update/inc/

+4


source


Js

db.test.update({id: "zxf"}, {$inc: {intValue: NumberInt(-1)}});

Java

Update update = new Update().inc(field, -1);

0


source







All Articles