Fields
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.
{
_id: "123",
field1: "abc",
field2: 1,
field3: {
sub_field1: "xyz",
sub_field2: 2
}
}Names
Similar to most document-oriented databases, you can only use strings to encode field names in documents.
For complete naming rules, see IDs, Paths, Strings, and Keywords.
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.
{
1: "numeric_fields_are_invalid_here",
"this_part": "numeric_fields_are_valid_here"
}Values
Field values can be encoded using various data types, including scalar type, providing flexibility in representing a wide range of information.
Following are the data types you can use to represent information in a Ditto document:
- REGISTER
- MAP
- ATTACHMENT
Each data type contains two distinct components: a merge behavior and a scalar value to store. (See Data-Handling Essentials)
Hierarchies
In the following structure, field properties are logically grouped to provide details about a specific car.
This structure includes an embedded object encapsulating both the GPS latitude and longitude coordinates, as well as the physical address where the car is located:
