Platform Manual
...
Complex Structures
Nested Hierarchy
if you need to represent a highly complex dataset in a document, you can embed a map data type within the document avoid using arrays in ditto due to potential merge conflicts when offline peers reconnect to the mesh and attempt to sync their updates, especially when multiple peers make concurrent updates to the same item within the array embedding map structures embedding a map provides a way for you to structure and organize related data within a single document to create a complex structure with multiple levels of hierarchy as in, you can embed a map within a map , within another map , within another map , and so on you can model relationships between your data using foreign key and key value relationships by way of embedded map for more information, see docid 45g2fwjgtrn8y9ne7w86j for example, the following snippet shows three levels of embedded maps details , engine , interior , and features { " id" { "vin" "123abc", "make" "toyota", "model" "corolla", "year" 2022, }, "details" { "engine" { "type" "gasoline", "displacement" "1 8l" }, "interior" { "seats" 5, "color" "black" }, "features" { "safety" { "airbags" 6, "antilockbrakes" true }, "technology" { "infotainment" "touchscreen", "navigation" true } } } } each level contains its own key value pairs and, if used, children level map you can represent key values using a register , attachment or another map for more information, see docid\ vofl0gukxq8ajsmmw7sgz benefits of embedding maps embedding a map is beneficial in scenarios where you need to manage a collection of items and continuously modify that collection over time; that is you want to link multiple data items with a single unique string identifier, but you anticipate that these data items are subject to concurrent edits over time as an example, the following snippet demonstrates a basic point of sale (pos) system where you need to keep track of the customer orders collection and, since multiple users can add and remove orders within the collection, you embed a map to represent the ordered items, where each key denotes an item id and the linked value indicates the quantity ordered pseudocode const order = { customername 'john doe', orderdate '2023 08 15', items { 'item123' 2, // item id quantity ordered 'item456' 5, 'item789' 1 } }; // inserting the order into the ditto collection await ditto store execute(` update into orders documents (\ order)`, { order });