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.subfield = value2
WHERE [condition]

In this syntax:

  • your_collection_name is the name of the collection in which you want to update data.
  • field1 = value1, field2.subfield = value2, ... represents the fields to be updated and their corresponding new value
  • [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 Nested Fields

Dot notation is available in 4.11 and later, with DQL_STRICT_MODE=false. Read more

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.

UPDATE your_collection_name 
SET
  field2.sub1  = 2,
  field2.sub2 = 'spring'
WHERE field1 = 'red'

Deleting Fields

UNSET is available in 4.11 and later.

In Ditto, fields need to be marked as “deleted” for other peers to know the field has been removed.

  • When unsetting a MAP, all children data types are iteratively unset.
  • Fields that are unset are ignored during subsequent DQL statements.
  • Calling UNSET on a large number of dynamically generated fields (for example, dynamically created keys in a CRDT map) may cause performance to degrade due to metadata accumulation over time. Benchmarks for this will vary depending on your dataset size and query cardinality. You can mitigate this accumulation by calling UNSET on a parent field (or deleting the document itself).
UPDATE your_collection_name
UNSET field_name 
WHERE _id = '123'