Batch Operations
Using batch operations
Manage collections with batch operations and key-value pairs using the id
key from each record or assigned key-value pairing. You can also use the id
key to update or delete records in a batch operation. Note: Your deployment tier has limits on how many id
keys you can use in a batch operation. (500-20,000 at a time depending on the deployment tier)
Batch Insert
Insert multiple records in a single request:
- HTTP
- JavaScript
- Python
POST https://{EKODB_API_URL}/api/batch/insert/{collection}
Content-Type: application/json
Authorization: Bearer {YOUR_TOKEN}
{
"records": [
{"id": "id1", "name": "User 1"},
{"id": "id2", "name": "User 2"}
]
}
# Response
{
"successful": ["id1", "id2"],
"failed": ["id3", "id4"]
}
const response = await fetch('https://{EKODB_API_URL}/api/batch/insert/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer {YOUR_TOKEN}' },
body: JSON.stringify({
records: [
{ name: "User 1" },
{ name: "User 2" }
]
})
});
const data = await response.json();
const successful = data.successful; // ['id1', 'id2']
const failed = data.failed; // ['id3', 'id4']
import requests
response = requests.post(
'https://{EKODB_API_URL}/api/batch/insert/users',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_TOKEN}'
},
json={
'records': [
{'name': 'User 1'},
{'name': 'User 2'}
]
}
)
data = response.json()
successful = data['successful'] # ['id1', 'id2']
failed = data['failed'] # ['id3', 'id4']
Batch Update
Update multiple records in a single request:
- HTTP
- JavaScript
- Python
PUT https://{EKODB_API_URL}/api/batch/update/{collection}
Content-Type: application/json
Authorization: Bearer {YOUR_TOKEN}
{
"updates": [
{"id": "id1", "name": "Updated 1"},
{"id": "id2", "name": "Updated 2"}
]
}
# Response
{
"successful": ["id1", "id2", ...],
"failed": ["id3", "id4", ...]
}
const response = await fetch('https://{EKODB_API_URL}/api/batch/update/users', {
method: 'PUT',
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer {YOUR_TOKEN}' },
body: JSON.stringify({
updates: [
{ id: "id1", name: "Updated 1" },
{ id: "id2", name: "Updated 2" }
]
})
});
const data = await response.json();
const successful = data.successful; // ['id1', 'id2']
const failed = data.failed; // ['id3', 'id4']
import requests
response = requests.put(
'https://{EKODB_API_URL}/api/batch/update/users',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_TOKEN}'
},
json={
'updates': [
{'id': 'id1', 'name': 'Updated 1'},
{'id': 'id2', 'name': 'Updated 2'}
]
}
)
data = response.json()
successful = data['successful'] # ['id1', 'id2']
failed = data['failed'] # ['id3', 'id4']
Batch Delete
Delete multiple records in a single request:
- HTTP
- JavaScript
- Python
DELETE https://{EKODB_API_URL}/api/batch/delete/{collection}
Content-Type: application/json
Authorization: Bearer {YOUR_TOKEN}
{
"ids": ["id1", "id2"]
}
# Response
{
"successful": ["id1", "id2", ...],
"failed": ["id3", "id4", ...]
}
const response = await fetch('https://{EKODB_API_URL}/api/batch/delete/users', {
method: 'DELETE',
headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer {YOUR_TOKEN}' },
body: JSON.stringify({
ids: ["id1", "id2"]
})
});
const data = await response.json();
const successful = data.successful; // ['id1', 'id2']
const failed = data.failed; // ['id3', 'id4']
import requests
response = requests.delete(
'https://{EKODB_API_URL}/api/batch/delete/users',
headers={
'Content-Type': 'application/json',
'Authorization': 'Bearer {YOUR_TOKEN}'
},
json={
'ids': ['id1', 'id2']
}
)
data = response.json()
successful = data['successful'] # ['id1', 'id2']
failed = data['failed'] # ['id3', 'id4']