Skip to main content

Overview

Each document in Ditto is a Map between a name (string) and a value. A value can be any other type supported in ditto, including Map.

Example

do {    // Insert JSON-compatible data into Ditto    try ditto.store["foo"].upsert([        "boolean": true,        "string": "Hello World",        "number": 10,        "map": ["key": "value"],        "array": [1,2,3],        "null": nil    ])}catch {    //handle error    print(error)}

Keys

Like JSON, Ditto only supports strings as keys in documents. That means attempting to insert a document like the following will throw an error:

{    1: "numeric_keys_are_invalid",    "this_part": "is_valid_though"}

Nested documents

Ditto does not support nesting documents. If you need to create relationships between documents, use a foreign key relationship by referencing the _id of the document. See Creating Relationships Between Documents for more information

Supported Types

For more information on all supported types, please continue to the next sections.

DescriptionMerge Semantics
RegisterA single primitive value (Number, String, Boolean, Binary File)Last Write Wins
CounterA special number capable of preserving incrementing and decrementing semanticsThe sum of all site's counters
MapA dictionary of name->value mappings where name is a string and value is any of the other typesUpdates merge
AttachmentA blob that you want to sync between devices without querying, diffing, or mergingN/A
ArrayA type of register that is represented as a list of values.Last Write Wins

.

New and Improved Docs

Ditto has a new documentation site at https://docs.ditto.live. This legacy site is preserved for historical reference, but its content is not guaranteed to be up to date or accurate.