# Collections

Collections enable you to store information to Stream. This allows you to use it inside your feeds, and to provide additional data for the personalized endpoints. Examples include products and articles, but any unstructured object (e.g. JSON) is a good match for collections.

Collection entries can be embedded inside activities and used to store nested data inside activities. When doing so, Stream will automatically enrich your activities with the current version of the data (see later section). Collection endpoints can be used both client-side and server-side except the batch methods that are only available server-side.

## Adding Collections

This method allows you to create a new entry on a named collection.

### Parameters

| name       | type   | description                                                          | default | optional |
| ---------- | ------ | -------------------------------------------------------------------- | ------- | -------- |
| collection | string | The name of the collection                                           | -       |          |
| entry_id   | string | The id of the entry, if not given an ID will be generated by Stream. | -       | ✓        |
| data       | object | The data related to the user                                         | -       |          |

<Tabs>

```csharp label="C#"
var collectionData = new Dictionary<string, object>();
collectionData.Add("name", "Cheese burger");
collectionData.Add("rating", "4 stars");
await client.Collections.AddAsync("food", collectionData, "cheese-burger");

// if you don't have an id on your side, just use null as the ID and Stream will generate a unique ID
await client.Collections.AddAsync("food", collectionData);
```

```js label="JavaScript"
await client.collections.add("food", "cheese-burger", {
  name: "Cheese Burger",
  rating: "4 stars",
});

// if you don't have an id on your side, just use null as the ID and Stream will generate a unique ID
await client.collections.add("food", null, {
  name: "Cheese Burger",
  rating: "4 stars",
});
```

```python label="Python"
client.collections.add("food", {"name": "Cheese Burger", "rating": "4 stars"}, id="cheese-burger")

# if you don't have an id on your side, Stream will generate a unique ID
client.collections.add("food", {"name": "Cheese Burger", "rating": "4 stars"})
```

```ruby label="Ruby"
client.collections.add(
  "food",
  {:name =&gt; "Cheese Burger", :rating =&gt; "4 stars"},
  :id =&gt; "cheese-burger"
)

# if you don't have an id on your side, Stream will generate a unique ID
client.collections.add("food", {:name =&gt; "Cheese Burger", :rating =&gt; "4 stars"})
```

```php label="PHP"
$client->collections()->add(
  "food", ["name" => "Cheese Burger", "rating" => "4 stars"], "cheese-burger"
);

// if you don't have an id on your side, Stream will generate a unique ID
$client->collections()->add(
  "food", ["name" => "Cheese Burger", "rating" => "4 stars"]
);
```

```java label="Java"
client.collections().add("food", new CollectionData("cheese-burger")
    .set("name", "Cheese Burger")
    .set("rating", "4 stars")).join();

// if you don't have an id on your side, just use null as the ID and Stream will generate a unique ID
client.collections().add("food", new CollectionData()
    .set("name", "Cheese Burger")
    .set("rating", "4 stars")).join();
```

```go label="Go"
obj := stream.CollectionObject{
		ID: "cheese-burger",
		Data: map[string]any{
			"name":  "Cheese Burger",
			"rating": "4 stars",
		},
	}
	resp, err := client.Collections().Add(context.TODO(), "food", obj)
	if err != nil {
		panic(err)
	}

	//if you don't have an id on your side, Stream will generate a unique ID
	obj := stream.CollectionObject{
		Data: map[string]any{
			"name":  "Cheese Burger",
			"rating": "4 stars",
		},
	}
	resp, err := client.Collections().Add(context.TODO(), "food", obj)
	if err != nil {
		panic(err)
	}
```

</Tabs>

<admonition type="info">

The max size of a collection can not exceed 50kB

</admonition>

## Retrieving Collections

After adding an entry to a collection, you can also retrieve it easily by its ID.

### Parameters

| name       | type   | description                | default | optional |
| ---------- | ------ | -------------------------- | ------- | -------- |
| collection | string | The name of the collection | -       |          |
| entry_id   | string | The id of the entry        | -       |          |

<Tabs>

```csharp label="C#"
await client.Collections.GetAsync("food", "cheese-burger");
```

```js label="JavaScript"
let response = client.collections.get("food", "cheese-burger");
```

```python label="Python"
client.collections.get("food", "cheese-burger")
```

```ruby label="Ruby"
client.collections.get("food", "cheese-burger")
```

```php label="PHP"
$client->collections()->get("food", "cheese-burger");
```

```java label="Java"
CollectionData collection = client.collections().get("food", "cheese-burger").join();
```

```go label="Go"
resp, err := client.Collections().Get(context.TODO(), "food", "cheese-burger")
	if err != nil {
		panic(err)
	}
```

</Tabs>

## Removing Collections

An entry can also be removed from a collection with its ID.

### Parameters

| name       | type   | description                | default | optional |
| ---------- | ------ | -------------------------- | ------- | -------- |
| collection | string | The name of the collection | -       |          |
| entry_id   | string | The id of the entry        | -       |          |

<Tabs>

```csharp label="C#"
await client.Collections.DeleteAsync("food", "cheese-burger");
```

```js label="JavaScript"
let response = client.collections.delete("food", "cheese-burger");
```

```python label="Python"
client.collections.delete("food", "cheese-burger")
```

```ruby label="Ruby"
client.collections.delete("food", "cheese-burger")
```

```java label="Java"
client.collections().delete("food", "cheese-burger").join();
```

```go label="Go"
_, err := client.Collections().Delete(context.TODO(), "food", "cheese-burger")
	if err != nil {
		panic(err)
	}
```

</Tabs>

<admonition type="info">

When you delete an entry from a collection any references will be converted to a missing reference error when reading feeds with [enrichment](/activity-feeds/docs/node/v2/collections-enrichment/).

</admonition>

## Updating Collections

A collection's entry data can be updated. Updates are propagated instantly to all activities embedding the entry.

### Parameters

| name       | type   | description                  | default | optional |
| ---------- | ------ | ---------------------------- | ------- | -------- |
| collection | string | The name of the collection   | -       |          |
| entry_id   | string | The id of the entry          | -       |          |
| data       | object | The data related to the user | -       |          |

<Tabs>

```csharp label="C#"
var collectionData = new Dictionary<string, object>();
collectionData.Add("name", "Cheese Burger");
collectionData.Add("rating", "1 star");
await client.Collections.UpdateAsync("food", "cheese-burger", collectionData);
```

```js label="JavaScript"
await client.collections.update("food", "cheese-burger", {
  name: "Cheese Burger",
  rating: "1 star",
});
```

```python label="Python"
client.collections.update("food", "cheese-burger", {"name": "Cheese Burger", "rating": "1 star"})
```

```ruby label="Ruby"
client.collections.update(
  "food",
  "cheese-burger",
  :data =&gt; {:name =&gt; "Cheese Burger", :rating =&gt; "1 stars"}
)
```

```php label="PHP"
$client->collections()->update("food", "cheese-burger",
  ["name" => "Cheese Burger", "rating" => "1 stars"]);
```

```java label="Java"
client.collections().update("food", new CollectionData("cheese-burger")
    .set("name", "Cheese Burger")
    .set("rating", "1 star")).join();
```

```go label="Go"
resp, err := client.Collections().Update(context.TODO(), "food", "cheese-burger", map[string]any{
		"name":  "Cheese Burger",
		"rating": "1 star",
	})
	if err != nil {
		panic(err)
	}
```

</Tabs>


---

This page was last updated at 2026-05-22T16:31:48.596Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/php/v2/collections-introduction/](https://getstream.io/activity-feeds/docs/php/v2/collections-introduction/).