# db.command.mul

Update command, indicating that the value of a field is automatically multiplied 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 multiplied by the original value 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 inc command.

Function signature:

function mul(value: number): Command

Sample code

Multiply the progress of a todo by 2:

const _ = db.command
db.collection('todos').doc('todo-id').update({
  data: {
    progress: _.mul(2)
  }
})
点击咨询小助手