Reputation: 65
Requirement: Get All documents where point < 90 and increment 'point' by +20 Data:
{ "_id" : 1, "student" : 1, "type" : "exam", "point" : 115 }
{ "_id" : 2, "student" : 2, "type" : "exam", "point" : 85 }
{ "_id" : 3, "student" : 3, "type" : "exam", "point" : 115 }
Query tried :
// query below
db.points.update({},{$inc:{point:20},point:{lt:110}},{multi:true})
On executing : fn[0] == '$'is seen and query has not affected any changes.
Upvotes: 1
Views: 1633
Reputation: 1
There is no where condition in your update
db.points.update({ point : { $lt: 90 } },{ $inc: { point:20 } },{multi:true})
point : { $lt: 90 } selects only documents where a value in point is lower then 90 and increases by 20
Upvotes: 0
Reputation: 26012
You can write query as follows :
db.points.update({point:{$lt:110}},{$inc:{point:20}},false,true)
Upvotes: 1