let response = try await client.createCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9
]
)
]
)
)Collections
Overview
Collections provide a way to attach data to activities that is shared between these activities and can be updated in a single place.
A typical use case is to track the status of an activity such as started, completed, or failed. Instead of having to update multiple activities when the status changes you can create a collection and add it to the activities that needs this data. When the status changes you only need to update the collection.
A collection consists of a name, an id and some data. You can think of the name as a namespace for the collection. A collection reference is a string that looks like <name>:<id> and is the unique identifier for the collection.
Data stored in collections can not be used in custom ranking or aggregation.
The batch endpoints supports up to 100 collections in a single request. Automatic deduplication will be applied, keeping the last occurrence only.
Creating Collections
The example below shows how to create a collection.
val response: Result<CreateCollectionsResponse> = client.createCollections(
request = CreateCollectionsRequest(
collections = listOf(
CollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9
)
)
)
)
)const response = await client.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});const response = await client.feeds.createCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9,
},
},
],
});final response = await client.createCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9,
},
),
],
);response, err := client.Feeds().CreateCollections(context.Background(), &getstream.CreateCollectionsRequest{
Collections: []getstream.CollectionRequest{
{
Name: "movies",
ID: "lord_of_the_rings",
Custom: map[string]any{
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
},
},
},
})
if err != nil {
log.Fatal("Error creating collections:", err)
}Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
CreateCollectionsRequest request = CreateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
CreateCollectionsResponse response = feeds.createCollections(request).execute().getData();$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9,
]
);
$response = $feedsClient->createCollections(
new GeneratedModels\CreateCollectionsRequest(collections: [$collection])
);var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9 }
}
};
var response = await _feedsV3Client.CreateCollectionsAsync(
new CreateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);response = client.feeds.create_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9,
}
)
]
)collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9
}
)
request = GetStream::Generated::Models::CreateCollectionsRequest.new(
collections: [collection]
)
response = client.feeds.create_collections(request)Updating Collections
The example below shows how to update a collection.
let response = try await client.updateCollections(
request: .init(
collections: [
.init(
name: "movies",
id: "lord_of_the_rings",
custom: [
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5
]
)
]
)
)val response: Result<UpdateCollectionsResponse> = client.updateCollections(
request = UpdateCollectionsRequest(
collections = listOf(
CollectionRequest(
name = "movies",
id = "lord_of_the_rings",
custom = mapOf(
"title" to "Lord of the Rings",
"genre" to "fantasy",
"rating" to 9.5
)
)
)
)
)const response = await client.updateCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9.5,
},
},
],
});const response = await client.feeds.updateCollections({
collections: [
{
name: "movies",
id: "lord_of_the_rings",
custom: {
title: "Lord of the Rings",
genre: "fantasy",
rating: 9.5,
},
},
],
});final response = await client.updateCollections(
collections: [
const CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
'title': 'Lord of the Rings',
'genre': 'fantasy',
'rating': 9.5,
},
),
],
);response, err := client.Feeds().UpdateCollections(context.Background(), &getstream.UpdateCollectionsRequest{
Collections: []getstream.CollectionRequest{
{
Name: "movies",
ID: "lord_of_the_rings",
Custom: map[string]any{
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5,
},
},
},
})
if err != nil {
log.Fatal("Error updating collections:", err)
}Map<String, Object> customData = new HashMap<>();
customData.put("title", "Lord of the Rings");
customData.put("genre", "fantasy");
customData.put("rating", 9.5);
CollectionRequest collection = CollectionRequest.builder()
.name("movies")
.id("lord_of_the_rings")
.custom(customData)
.build();
UpdateCollectionsRequest request = UpdateCollectionsRequest.builder()
.collections(List.of(collection))
.build();
UpdateCollectionsResponse response = feeds.updateCollections(request).execute().getData();$collection = new GeneratedModels\CollectionRequest(
name: 'movies',
id: 'lord_of_the_rings',
custom: (object)[
'title' => 'Lord of the Rings',
'genre' => 'fantasy',
'rating' => 9.5,
]
);
$response = $feedsClient->updateCollections(
new GeneratedModels\UpdateCollectionsRequest(collections: [$collection])
);var collection = new CollectionRequest
{
Name = "movies",
ID = "lord_of_the_rings",
Custom = new Dictionary<string, object>
{
{ "title", "Lord of the Rings" },
{ "genre", "fantasy" },
{ "rating", 9.5 }
}
};
var response = await _feedsV3Client.UpdateCollectionsAsync(
new UpdateCollectionsRequest { Collections = new List<CollectionRequest> { collection } }
);response = client.feeds.update_collections(
collections=[
CollectionRequest(
name="movies",
id="lord_of_the_rings",
custom={
"title": "Lord of the Rings",
"genre": "fantasy",
"rating": 9.5,
}
)
]
)collection = GetStream::Generated::Models::CollectionRequest.new(
name: 'movies',
id: 'lord_of_the_rings',
custom: {
title: 'Lord of the Rings',
genre: 'fantasy',
rating: 9.5
}
)
request = GetStream::Generated::Models::UpdateCollectionsRequest.new(
collections: [collection]
)
response = client.feeds.update_collections(request)Deleting Collections
The example below shows how to delete a collection.
let response = try await client.deleteCollections(
request: .init(
collectionRefs: ["movies:lord_of_the_rings"]
)
)val response: Result<DeleteCollectionsResponse> = client.deleteCollections(
request = DeleteCollectionsRequest(
collectionRefs = listOf("movies:lord_of_the_rings")
)
)const response = await client.deleteCollections({
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.deleteCollections({
collection_refs: ["movies:lord_of_the_rings"],
});final response = await client.deleteCollections(
collectionRefs: ['movies:lord_of_the_rings'],
);response, err := client.Feeds().DeleteCollections(context.Background(), &getstream.DeleteCollectionsRequest{
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error deleting collections:", err)
}DeleteCollectionsRequest request = DeleteCollectionsRequest.builder()
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
DeleteCollectionsResponse response = feeds.deleteCollections(request).execute().getData();$response = $feedsClient->deleteCollections(
new GeneratedModels\DeleteCollectionsRequest(
collectionRefs: ['movies:lord_of_the_rings']
)
);var response = await _feedsV3Client.DeleteCollectionsAsync(
new DeleteCollectionsRequest { CollectionRefs = new List<string> { "movies:lord_of_the_rings" } }
);response = client.feeds.delete_collections(
collection_refs=["movies:lord_of_the_rings"]
)request = GetStream::Generated::Models::DeleteCollectionsRequest.new(
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.delete_collections(request)Reading Collections
The example below shows how to read a collection.
let response = try await client.readCollections(
request: .init(
collectionRefs: ["movies:lord_of_the_rings"]
)
)val response: Result<ReadCollectionsResponse> = client.readCollections(
request = ReadCollectionsRequest(
collectionRefs = listOf("movies:lord_of_the_rings")
)
)const response = await client.readCollections({
collection_refs: ["movies:lord_of_the_rings"],
});const response = await client.feeds.readCollections({
collection_refs: ["movies:lord_of_the_rings"],
});final response = await client.readCollections(
collectionRefs: ['movies:lord_of_the_rings'],
);response, err := client.Feeds().ReadCollections(context.Background(), &getstream.ReadCollectionsRequest{
CollectionRefs: []string{"movies:lord_of_the_rings"},
})
if err != nil {
log.Fatal("Error reading collections:", err)
}ReadCollectionsRequest request = ReadCollectionsRequest.builder()
.collectionRefs(List.of("movies:lord_of_the_rings"))
.build();
ReadCollectionsResponse response = feeds.readCollections(request).execute().getData();$response = $feedsClient->readCollections(
new GeneratedModels\ReadCollectionsRequest(
collectionRefs: ['movies:lord_of_the_rings']
)
);var response = await _feedsV3Client.ReadCollectionsAsync(
new ReadCollectionsRequest { CollectionRefs = new List<string> { "movies:lord_of_the_rings" } }
);response = client.feeds.read_collections(
collection_refs=["movies:lord_of_the_rings"]
)request = GetStream::Generated::Models::ReadCollectionsRequest.new(
collection_refs: ['movies:lord_of_the_rings']
)
response = client.feeds.read_collections(request)