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
markhorrocks
source
to share
3 answers
Increase by -1?
$inc: {score: -1}
+38
Dan Dascalescu
source
to share
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
bengott
source
to share
Js
db.test.update({id: "zxf"}, {$inc: {intValue: NumberInt(-1)}});
Java
Update update = new Update().inc(field, -1);
0
zxf 曾 爷
source
to share