Ditto stores data records as JSON-like documents. Internally these documents are CRDTs, which are a binary representation of JSON documents designed for automatic conflict resolution.
_id
: STRING
name
: STRING
age
: NUMBER
email
: STRING
address
: OBJECT
is_active
: BOOLEAN
created_at
: DATE
_id
field that acts as a primary key. If an inserted document omits the _id
field, Ditto automatically generates a unique identifier for the _id
field.
Once set for a given document, the _id
field cannot be changed. The same document contents inserted with a different _id
will be treated as a new document within Ditto.
The _id
is required for all documents and can be any JSON data type.
While generating a unique identifier is the default behavior, typically you will provide your own _id
values represented as a more complex object (acting as a composite key).
For example, the following document includes a _id
field with a complex object:
_id
object or by breaking it down into its individual components.
_id
field when designing your data model, as this is used for authorization rules within Ditto. For more information, see Authorization.
strings
to encode field names in documents.
For complete naming rules, see IDs, Paths, Strings, and Keywords.
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
.Instead using a JSON object within a MAP
allows you to automatically merge the contents of the MAP
when offline peers reconnect to the mesh.MAP
or REGISTER
.
You can read more about CRDTs in Syncing Data.
_id
.cars
and owners
, where each car has a corresponding owner, every document in the cars
collection would include a field containing the ID of a document in the owners
collection.
For example: