MongoDB: Decrement all documents with field value higher then defined

时间:2015-09-19 18:50:16

标签: javascript mongodb

I want to decrement all documents with order greater then a given value and a given parent value:

var order = 5, parent = "books";
Articles.update({ parent: parent, order > order }, $inc { order: -1 }, {multi: true});

In this example all documents with parent = books and with a higher order value of 5 are updated to an decremented order value. I don't know if this is possible with one line or do I have to start the update() multiple times in a loop?

0 个答案:

没有答案