Clauses
UPDATE
The UPDATE
operation modifies the content of existing documents in a collection.
With an UPDATE
statement, you can update specific fields within the documents based on specified conditions:
DQL
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 Multiple Fields
The following snippet shows an example of using UPDATE to set multiple fields:
DQL
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.
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 callingUNSET
on a parent field (or deleting the document itself).