// first we add our object to the food collection
let cheeseBurger = await client.collections.add("food", "123", {
name: "Cheese Burger",
ingredients: ["cheese", "burger", "bread", "lettuce", "tomato"],
});
// the object returned by .add can be embedded directly inside of an activity
await userFeed.addActivity({
actor: client.currentUser,
verb: "grill",
object: cheeseBurger,
});
// if we now read the feed, the activity we just added will include the entire full object
await userFeed.get();
// we can then update the object and Stream will propagate the change to all activities
await cheeseBurger.update({
name: "Amazing Cheese Burger",
ingredients: ["cheese", "burger", "bread", "lettuce", "tomato"],
});Enrichment
Enrichment of Collection Entries
Objects stored inside collections can be embedded inside activities or user objects. This allows you to integrate with Stream without building a complex integration with another database. Stream's collections can be used as your data source for data enrichment.
//first we add our object to the food collection
obj := stream.CollectionObject{
Data: map[string]any{
"name": "Cheese Burger",
"ingredients": []string{"cheese", "burger", "bread", "lettuce", "tomato"},
},
}
resp, err := client.Collections().Add(context.TODO(), "food", obj)
if err != nil {
panic(err)
}
// then we embed a reference to the entry we created before
activity := stream.Activity{
Actor: "jim",
Verb: "grill",
Object: client.Collections().CreateReference("food", resp.ID),
}
_, err := userFeed.AddActivity(context.TODO(), activity)
if err != nil {
panic(err)
}
// if we now read the feed, the activity we just added will include the entire full object
resp, err := userFeed.GetEnrichedActivities(context.TODO())
if err != nil {
panic(err)
}