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.
A document must always belong to a collection, even if only one document is associated with that collection name.
There's no explicit step to creating a collection; when you create a document with a specified collection name, Ditto automatically handles the referencing of that collection. That is, the collection name is assigned implicitly by the documents themselves. When you save a document and associate it with a particular collection name (like "cars" or "boats"), Ditto internally manages the collection. If the specified collection name doesn't exist yet, Ditto creates it as soon as the first document is associated with that name.
While it is typically common for all documents in a collection to have the same structure, it is not a technical requirement.
For example, all documents referencing cars can go in the "cars" collection, and boat documents in the "boats" collection. You can create any number of collections that best represent your data model.
Ditto queries against collections, not documents.
For example, querying an entire cars collection:
When querying a collection that contains data types other than REGISTER — so when you're querying for a MAP or ATTACHMENT type — it is crucial to declare their types. Failing to do so will leave Ditto unsure about where to search.
To declare their 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:
For complete DQL syntax, see Ditto Query Language > Types and Definitions
Double underscore (__) denotes a Ditto system collection and is a reserved identifier prefix for collections.