# db.command.set

Update command. Sets the value of a field to be equal to the specified value.

Function signature:

function set(value: any): Command

Compared with the method in which pure JS objects are imported, this method has an advantage of specifying the value of a field to be equal to one object:

// In the following method, only the style.color is updated to red, and the style is not updated to { color: 'red' }, without affecting other fields in the style.
db.collection('todos').doc('doc-id').update({
  data: {
    style: {
      color: 'red'
    }
  }
})

// In the following method, the style is updated to { color: 'red', size: 'large' }.
db.collection('todos').doc('doc-id').update({
  data: {
    style: _.set({
      color: 'red',
      size: 'large'
    })
  }
})