// first we add our object to the food collection
var collectionData = new Dictionary<string, object>();
collectionData.Add("name", "Cheese Burger");
collectionData.Add("ingredients", new[] { "cheese", "burger", "bread", "lettuce", "tomato" });
var cheeseBurger = await client.Collections.AddAsync("food", collectionData, "123");
// the object returned by .add can be embedded directly inside of an activity
var activity = new Activity("jim", "grill", cheeseBurger.Ref("food"));
await userFeed.AddActivityAsync(activity);
// if we now read the feed, the activity we just added will include the entire full object
await userFeed.GetEnrichedFlatActivitiesAsync();
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
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'],
});
# first we add our object to the food collection
cheese_burger = client.collections.add(
"food",
data={
"name": "Cheese Burger",
"ingredients": ["cheese", "burger", "bread", "lettuce", "tomato"],
},
)
# then we embed a reference to the entry we created before
user_feed.add_activity(
{
"actor": "jim",
"verb": "grill",
"object": client.collections.create_reference(
"food", cheese_burger["id"]
),
}
)
# if we now read the feed, the activity we just added will include the entire full object
user_feed.get(enrich=True)
# first we add our object to the food collection
cheese_burger = client.collections.add(
"food",
:data => {
:name => "Cheese Burger",
:ingredients => ["cheese", "burger", "bread", "lettuce", "tomato"],
},
)
# then we embed a reference to the entry we created before
user_feed.add_activity({
:actor => "jim",
:verb => "grill",
:object => client.collections.create_reference(
"food", cheese_burger["id"]
),
})
# if we now read the feed, the activity we just added will include the entire full object
user_feed.get(:enrich => true)
// first we add our object to the food collection
$client->collections()->add(
"food", ["name" => "Cheese Burger", "rating" => "4 stars"], "cheese-burger"
);
// then we embed a reference to the entry we created before
$user_feed->addActivity(
["actor" => "jim", "verb" => "grill",
"object" => $client->collections()->createReference("food", "cheese-burger")]
);
// if we now read the feed, the activity we just added will include the entire full object
$user_feed->getActivities(0, 1, null, true);
// first we add our object to the food collection
CollectionData cheeseBurger = client.collections().add("food", new CollectionData("123")
.set("name", "Cheese Burger")
.set("ingredients", Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))).join();
// the object returned by .add can be embedded directly inside of an activity
userFeed.addActivity(Activity.builder()
.actor(createUserReference("john-doe"))
.verb("grill")
.object(createCollectionReference(cheeseBurger.getCollection(), cheeseBurger.getID()))
.build()).join();
// if we now read the feed, the activity we just added will include the entire full object
userFeed.getEnrichedActivities();
// we can then update the object and Stream will propagate the change to all activities
client.collections().update(cheeseBurger.getCollection(), cheeseBurger
.set("name", "Amazing Cheese Burger")
.set("ingredients", Lists.newArrayList("cheese", "burger", "bread", "lettuce", "tomato"))).join();
//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)
}
// first we add our object to the food collection
let cheeseBurger = Food(name: "Cheese Burger", rating: 4, id: "cheese-burger")
// setup an enriched activity type
typealias UserFoodActivity = EnrichedActivity<user, food,="" string="">
client.add(collectionObject: cheeseBurger) { _ in
// the object returned by .add can be embedded directly inside of an activity
userFeed.add(UserFoodActivity(actor: client.currentUser!, verb: 'grill', object: cheeseBurger)) { _ in
// if we now read the feed, the activity we just added will include the entire full object
userFeed.get(typeOf: UserFoodActivity.self) { result in
let activities = try! result.get().results
// we can then update the object and Stream will propagate the change to all activities
cheeseBurger.name = "Amazing Cheese Burger"
client.update(collectionObject: cheeseBurger) { result in /* ... */ }
}
}
}</user,>
// first we add our object to the food collection
final cheeseBurger = await client.collections.add('food', {
'name': 'Cheese Burger',
'ingredients': ['cheese', 'burger', 'bread', 'lettuce', 'tomato'],
});
// the object returned by .add can be embedded directly inside of an activity
final activityId = await user1.addActivity(Activity(
actor: client.currentUser!.userId,
verb: 'grill',
object: cheeseBurger.ref,
));
// if we now read the feed, the activity we just added will include the entire full object
await user1.getEnrichedActivities();
// we can then update the object and Stream will propagate the change to all activities
await client.collections.update(cheeseBurger.copyWith(data: {
'name': 'Amazing Cheese Burger',
'ingredients': ['cheese', 'burger', 'bread', 'lettuce', 'tomato'],
}));
On this page: