How to increment MongoDB Field value?

Views: 38 Ask New Question


On By

1 Answer


Use the following to increment a field value by one.

db.getCollection('posts').update({ "_id" : ObjectId("document_id") } , {   $inc: {  views : 1 } }, {upsert: true} )
On By


Answer This Question