---
title: Collections
slug: v4-4/-sf0Km4y3-UKpYVn_b5dF
docTags: 
createdAt: 2023-08-13T16:32:45.845Z
---

At a high level, Ditto queries execute on specific *collections* and are utilized to filter and narrow down the contents of those collections.

A collection is a set of documents categorized together. For example, you would group all documents related to cars in a `"cars"` collection.

# Creating a Collection&#x20;

Using `ditto.store.collection` and `upsert` methods, create your collection. For example, `cars`:&#x20;

:::hint{type="info"}
For more information, see [CRUD Operations](docId:1CEXFnSWhjeqa_R6yyL-8).
:::

:::CodeblockTabs
pseudocode

```javascript
ditto.store.collection("cars").upsert({
  id: 123,
  make: "Toyota",
  model: "Corolla",
  year: 2022,
  color: "Blue"
});
```
:::

# Referencing a Collection&#x20;

Instead of inspecting the many fields that documents contain, you can reference a shared collection making it easy to retrieve and store information.&#x20;

Ditto syncs and queries documents using a combination of collection name and document identifier. The document ID serves as the primary identifier within the collection.

As long as a collection contains at least one document, you can continue referencing it.&#x20;

Following is an example of a reference to cars in a replication query using the `find` method:

:::CodeblockTabs
pseudocode

```javascript
const collection = await ditto.store.collection('cars').find("color == 'red' && mileage <=5000")
```
:::

