---
title: Collections
slug: v4-7/document-model/collections
docTags: 
createdAt: 2023-08-13T16:32:45.845Z
---

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.

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/fcqm-eUpUunzxjkGDX_4y_document-demo-table.png" size="74" width="2836" height="1540" position="flex-start" showCaption="false"}

# 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.&#x20;

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

For more information, see [Bad Pattern: Large Documents](docId\:B4Bj0z0xxoHo2KD13tYSL).

# 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

:::::VerticalSplit{layout="middle"}
:::VerticalSplitItem
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.
:::

::::VerticalSplitItem
:::CodeblockTabs
DQL

```sql
SELECT * FROM cars
```
:::
::::
:::::

## 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.&#x20;

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

:::CodeblockTabs
DQL

```sql
SELECT * FROM COLLECTION cars (properties MAP)
```
:::

For complete DQL syntax, see *Ditto Query Language&#x20;*> [Types and Definitions](docId\:so0GVjLPrqJbUaBmG39xA).
