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:
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.Here is an example of a basic UPDATE operation:
The following snippet shows an example of using UPDATE to set multiple 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.
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.
MAP
, all children data types are iteratively unset.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).