Document Model

Collections

Ditto syncs and queries documents through a combination of collection names and document identifiers (_id). A collection is a grouping of documents, like tables in a relational database system but far simpler and more flexible.

Document image


Structuring Collections

While it is good practice for documents within a collection to share a similar structure for instance, all car-related documents stored in the cars collection contain fields 'make', 'model', and 'year' structural uniformity is not mandatory.

There is no limit to the number of collections you can have in your data model, so create as many collections as you need.

Managing Collections

Every document must be associated with a collection, even if only one document exists within that collection.

There are no explicit steps to managing collections; Ditto implicitly creates collections, assigns documents, and organizes references based on the documents being stored.

Querying Collections

When querying, database interactions occur with collections rather than individual documents.

For instance, the query on the right searches the entire cars collection once executed.

DQL


Declaring Types

To declare types, prefix the collection name with the COLLECTION keyword followed by a type definition. A type definition expresses the data types for the fields.

For example, here querying is against the cars collection with a field properties of data type MAP:

DQL


For complete DQL syntax, see Ditto Query Language > Types and Definitions.

Updated 23 Oct 2024
Did this page help you?