Document Model
Data is stored in Ditto as a schema-flexible unit referred to as a document. The data that documents contain can be exposed using a variety of data formats; however, JSON format is most common.
A set of documents grouped together is referred to as a collection. A collection can be thought of like a table in a relational database table — but with greater flexibility in terms of the data it can hold — and the documents in a collection like table rows.
The following table provides a basic definition of a document; the fundamental unit of data storage in Ditto:
For more information, see Ditto Basics > Data Structures and Types.
Structure | A Ditto document is a group of key-value pairs: |
---|---|
Content |
|
Identification | Each document has a unique _id field that acts at a primary key. The _id field is automatically added by Ditto if not provided during document creation. |
Flexibility | Ditto is schema-less, meaning that documents within the same collection do not need to have the same set of fields or structure. This flexibility allows for the evolution of data models over time without requiring changes to existing data. |
A document consists of sets of fields that self-describe the data it encodes. Each set signifies a single pair of two associated elements:
- The name identifying the field.
- The value that holds the data.
Similar to most document-oriented databases, you can only use strings to encode field names in documents.
For complete naming rules, see Ditto Query Language > IDs, Paths, Strings, and Keywords > Identifier Rules.
If you attempt to insert a type other than a string for a field property, as demonstrated in the following snippet, you will receive an error message:
In the following structure, the location field property is logically grouped with details about the car, such as its make, year, and color.
It contains nested fields. also referred to as subfields, representing both the coordinates and the address where the car is located:
Values can be encoded using various data types, including scalar type, providing flexibility in representing a wide range of information.
Data types provide flexibility in representing a range of information and consist of a merge behavior plus a scalar value. Data types include REGISTER, MAP, and ATTACHMENT
For more information and how-to instructions, see Platform Manual > Data Types.