OneCompiler

How to increment MongoDB Field value?

1 Answer

8 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} )
8 years ago by Karthik Divi