How to increment MongoDB Field value?


1 Answer

7 years ago by

Use the following to increment a field value by one.

db.getCollection('posts').update({ "_id" : ObjectId("document_id") } , {   $inc: {  views : 1 } }, {upsert: true} )
7 years ago by Karthik Divi