logo image

How to increment MongoDB Field value?


1 Answer

1 year 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} )
1 year ago by Megamind