# db.command.inc

Update command, indicating that the value of a field is automatically increased by the specified value. This is an atomic operation, and the advantage of using this operation command instead of reading data first, and then adding the data and writing it back is as follows:

  1. Atomicity: When multiple users write data to a field at the same time, the value of the field is automatically increased by 1 in the database, and new data does not overwrite previous data.
  2. One network request is reduced: There is no need to read the data first and then write it back.

Same as the mul command.

Function signature:

function inc(value: number): Command

Sample code

Automatically increase the progress of a todo by 10:

const _ = db.command
db.collection('todos').doc('todo-id').update({
  data: {
    progress: _.inc(10)
  }
})