Node

Batch Endpoints

LAST EDIT Feb 09 2021

You can use batch endpoints to insert, delete or read multiple entries at once. These three endpoints are only available when running Stream on your backend.

Upsert

Copied!

Upsert allows you to insert or update up to 1000 entries with a single API call. The payload is an array of entries. Entries that already exist (same ID) will be updated with the new version.

nametypedescriptiondefaultoptional
collectionstringThe name of the collection-
entry_idstringThe id of the entry, if not given an ID will be generated by Stream-
dataobjectThe data related to the user-

1
2
3
client.collections.upsert('user', [ 
    {id: '123', name: 'johndoe', favorite_color: 'blue'} 
]);
1
2
# Update the information for user with id 123 
client.collections.upsert('user', [{'id': '123', 'username': 'johndoe', 'favorite_color': 'blue'}])
1
2
# Update the information for user with ID 123 
client.collections.upsert('user', [{id: '123', name: 'johndoe', favorite_color: 'blue'}])
1
2
3
4
5
6
7
8
// Update the information for user with id 123 
$client->collections()->upsert('user', [ 
    [ 
        'id' => '123', 
        'username' => 'johndoe', 
        'favorite_color' => 'blue', 
    ] 
]);
1
2
3
4
// Update the information for user with ID 123 
client.collections().upsert("user", new CollectionData("123") 
        .set("username", "johndoe") 
        .set("favorite_color", "blue")).join();
1
2
3
4
5
6
7
8
9
10
11
12
// Update the information for user with ID 123 
object := stream.CollectionObject{ 
	ID:   "123", 
	Data: map[string]interface{}{ 
		"name": "johndoe", 
		"favorite_color": "blue", 
	}, 
} 
err = client.Collections().Upsert("user", object) 
if err != nil { 
	panic(err) 
}
1
2
3
4
5
// Update the information for user with ID 123 
var obj = new CollectionObject("123"); 
obj.SetData("name", "johndoe"); 
obj.SetData("favorite_color", "blue"); 
await client.Collections.Upsert("user", obj);

Select

Copied!

This method allows you to retrieve up to 1000 entries by ID.

nametypedescriptiondefaultoptional
foreign_idslist of stringThe list of collection:id entries to retrieve (eg. ["visitor:123", "visitor:124"])-
dataobjectThe data related to the user-
1
2
// select the entries with ID 123 and 124 from items collection 
let objects = await client.collections.select('items', ['123', '124']);
1
2
# select the entries with ID 123 and 124 from items collection 
objects = client.collections.select('items', ["123", "124"])
1
2
# select the entries with ID 123 and 124 from items collection 
objects = client.collections.select('items', ['123', '124'])
1
2
// select the entries with ID 123 and 124 from items collection 
$objects = $client->collections()->select('items', ['123', '124']);
1
2
// select the entries with ID 123 and 124 from items collection 
List<collectiondata> objects = client.collections().select("items", "123", "124").join();</collectiondata>
1
2
3
4
5
// select the entries with ID 123 and 124 from items collection 
objects, err := client.Collections().Select("items", "123", "124") 
if err != nil { 
	panic(err) 
}
1
2
// select the entries with ID 123 and 124 from items collection 
var objects = await client.Collections.Select("items", "123", "124");

Delete Many

Copied!

This method allows you to delete up to 1000 entries by ID.

nametypedescriptiondefaultoptional
collectionstringThe name of the collection-
idslist of stringsThe list of id to remove-
1
2
// delete the entries with ID 123 and 124 from visitor collection 
client.collections.deleteMany('visitor', ['123', '124']);
1
2
# delete the entries with ID 123 and 124 from visitor collection 
response = client.collections.delete_many('visitor', ["123", "124"])
1
2
# delete the entries with ID 123 and 124 from visitor collection 
client.collections.delete_many('visitor', ['123', '124'])
1
2
// delete the entries with ID 123 and 124 from visitor collection 
$response = $client-&gt;collections()-&gt;deleteMany('visitor', ["123", "124"]);
1
2
// delete the entries with ID 123 and 124 from visitor collection 
client.collections().deleteMany("visitor", "123", "124").join();
1
2
3
4
5
// delete the entries with ID 123 and 124 from visitor collection 
err = client.Collections().DeleteMany("visitor", "123", "124") 
if err != nil { 
	panic(err) 
}
1
2
// delete the entries with ID 123 and 124 from visitor collection 
await client.Collections.Delete("visitor", "123", "124");

When you delete an entry from a collection any references will be converted to a missing reference error when reading feeds with enrichment.