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 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.
For example, the following snippet shows three levels of embedded maps: details, engine, interior, and features.
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 Data Types.
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: