The query below increases score
by one
.
db.people.findAndModify({
query: { name: "Andy" },
update: { $inc: { score: 1 } }
})
But, is it possible to do more than just increase the score
. I would like to, increase the score
and also compute avg_field
for same document.
db.people.findAndModify({
query: { name: "Andy" },
update: { $inc: { score: 1 }, avg_field : {x divide by new score value} }
})
I might be able to use function to compute all that, but still that will not help inserting updated values. I would like to keep the operation atomic and hence trying to update in the same query.
Suggestions?