Activity Feeds v3 is in beta — try it out!

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.

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)
}

Overview of the collection model

CollectionResponse

NameTypeDescriptionConstraints
created_atnumberWhen the collection was created-
customobjectCustom data for the collection-
idstringUnique identifier for the collection within its nameRequired
namestringName/type of the collectionRequired
updated_atnumberWhen the collection was last updated-
user_idstringID of the user who owns this collection-

Updating Collections

The example below shows how to update a collection.

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)
}

Deleting Collections

The example below shows how to delete a collection.

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)
}

Reading Collections

The example below shows how to read a collection.

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)
}
© Getstream.io, Inc. All Rights Reserved.