1
UPDATEWhen executing UPDATE to apply changes, only the minimum data necessary to enforce all peers converge on one view of the data sync across the mesh. (Updating)2
INSERTWhile INSERT operations modify all provided fields, even if they remain unchanged. (Inserting)Updating
To optimize performance and reduce unnecessary overhead, apply most updates in your app through theUPDATE method instead.
For the full DQL syntax, see Ditto Query Language UPDATE.
UPDATE operation on the cars collection:
MAP Data Type
To add aMAP to a document, use the dot syntax, which allows you to edit multiple child fields within a single MAP:
Multiple Documents
Modify multiple documents simultaneously based on a specified condition. For example, here is a snippet demonstrating theUPDATE operation modifying all documents in the cars collection that are currently red, and changing their color to blue.
After the update, you can reference the documents modified by the mutatedDocumentIDs method on the result of the update.
Inserting with UPDATE
TheINSERT operation provides conflict policy options to override default behavior if a document with the same ID already exists.
For the full DQL syntax, see Ditto Query Language INSERT.
ON ID CONFLICT DO UPDATE policy, inserted documents automatically apply updates for all provided fields.
Nested MAPs
If you need to represent and organize highly complex data in a hierarchical structure, consider embedding aMAP within another MAP to establish a
parent-child relationship within a document as follows.
The Kotlin example uses UPDATE with dot notation to change
top_map.nested_map.color to 'red' in the existing car with ID '123'
(see Updating a Nested MAP). The other language tabs
use INSERT to add a new document with nested MAPs.
All examples below assume DQL_STRICT_MODE=false, the default in SDK 5.0 and
later. With this setting, collection definitions are not required. See
Strict Mode for version-specific configuration.
Updating a Nested MAP
Use dot notation to update a single field inside a nested MAP. These examples changetop_map.nested_map.color in the existing car '123' in the cars
collection, and leave the sibling fields in both MAPs and the rest of the
document unchanged. The INSERT examples above use your_collection_name;
create the document in cars before running this UPDATE.