With an UPDATE statement, you can update specific fields within the documents based on specified conditions:

DQL
UPDATE your_collection_name
SET field1 = value1, field2 -> [mutator], ...
WHERE [condition]

In this syntax:

  • your_collection_name is the name of the collection in which you want to update data.
  • field1 = value1, field2 -> [mutator], ... represents the fields to be updated and their corresponding new value or functional mutator.
  • [condition] is the expression or set of conditions that determine which documents should be included in the result set.

Basic UPDATE

Here is an example of a basic UPDATE operation:

DQL
UPDATE your_collection_name
SET field1 = 'blue'
WHERE _id = '123'

UPDATE Multiple Fields

The following snippet shows an example of using UPDATE to set multiple fields:

DQL
UPDATE your_collection_name
SET
  field1 = 'blue',
  field2 = 0
WHERE _id = '123'

UPDATE with MAP Type

When updating fields nested in a MAP, specify the field-value pairs you want to update.

For MAP syntax, see Ditto Query Language > Types and Definitions > Map Operations.

DQL
UPDATE COLLECTION your_collection_name (field2 MAP)
SET
  field2 -> (
     sub1 = 2,
     sub2 = 'spring'
  )
WHERE field1 = 'red'

Deleting Fields

A field can be deleted by using the tombstone keyword. A tombstone is a flag signaling to remote peers that the field is deleted from the document.

DQL
UPDATE your_collection_name
SET your_field_name -> tombstone()
WHERE _id = '123'

For more information and how-to instructions, see Ditto Query Language > Types and Definitions > Tombstone Operation.