Section: Field update operators

Increment a numeric field

javascript
javascript
db.posts.updateOne({ _id: 1 }, { $inc: { views: 1 } })
Explanation

Ideal for counters, sequence-like values, and metrics.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Field update operators
Remove a field
Delete one or more fields from matched documents.
OpenIn sheetjavascriptsame section
Rename a field
Change a field name in-place.
OpenIn sheetjavascriptsame section
Stamp an update time
Set a field to the current date.
OpenIn sheetjavascriptsame section
Append to an array
Push one item onto an array field.
OpenIn sheetjavascript1 tag match
Append only if missing
Use `$addToSet` to avoid duplicates.
OpenIn sheetjavascript1 tag match
Remove array values
Delete matching values from an array.
OpenIn sheetjavascript1 tag match