> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ditto.live/llms.txt
> Use this file to discover all available pages before exploring further.

# Databases and Collections

> Ditto stores data records as documents (specifically JSON-like documents) which are gathered together in collections. An database stores one or more collections of documents.

## Databases

In Ditto, a database is a grouping of collections. All databases that embed the Ditto SDK and share the same database ID will automatically form a mesh network and synchronize data with each other, either directly or via Ditto Server.

## Collections

Ditto stores documents in collections. Collections are analogous to tables in relational databases.
Collections allow you to group similar documents together within the same namespace.

<Frame>
  <img src="https://mintcdn.com/ditto-248bc0d1/_UNdP98-Q-K7lTyJ/images/v4.9/doc-model-2.webp?fit=max&auto=format&n=_UNdP98-Q-K7lTyJ&q=85&s=7f70dec65bc056fe65593a5d6f42266b" width="600" height="326" data-path="images/v4.9/doc-model-2.webp" />
</Frame>

### 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 manage collections; Ditto implicitly creates collections when you first store data for that collection.

### Querying Collections

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

For instance, the query below searches the entire `cars` collection once executed.

```sql theme={null}
SELECT * FROM cars
```

You can read more about accessing data within collections in [Accessing Data](/key-concepts/accessing-data).
