Creating Collections
Auth required:
Authorization: <main_api_key>header.
A Collection must be created before you can insert any data. During creation, you must specify whether your record IDs will be number or string, and which JSON fields should be searchable. Because ID selection directly impacts database indexing, please consider the following performance guidelines:
- Use sequential IDs: Whether you choose
numberorstring, keeping them sequential is critical. Completely randomIDs(such asUUIDv4) will drastically degrade write performance. - Opt for
numberfor maximum speed: For the absolute highest throughput, lowest latency and best storage utilization, use numeric IDs.
Filtering is not supported directly. However, you can easily bypass this by structuring your collections. For example, if you want to search messages by a specific user, you can simply create a dedicated collection named
messages:[userId].
Example
js
const collection = await client.createCollection({
name: "messages",
idType: "number",
searchableFields: ["title", "body"],
});
// { name: "messages", id_type: "number", searchable_fields: ["title", "body"] }js
await fetch("http://localhost:3000/collections", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "SecretApiKey",
},
body: JSON.stringify({
name: "messages",
id_type: "number",
searchable_fields: ["title", "body"],
}),
});sh
# POST /collections
#
# Request Body:
# {
# "name": "messages",
# "id_type": "number",
# "searchable_fields": ["title", "body"]
# }
#
# Response: 201 { "name": "…", "id_type": "…", "searchable_fields": ["…"] }
curl -X POST http://localhost:3000/collections \
-H "Content-Type: application/json" \
-H "Authorization: SecretApiKey" \
-d '{"name": "messages", "id_type": "number", "searchable_fields": ["title", "body"]}'Endpoint Definition
| Field | Value |
|---|---|
| Method | POST |
| Path | /collections |
Request Body
| Param | Type | Description |
|---|---|---|
name | string | Collection name |
id_type | string | "number" or "string" |
searchable_fields | array of string | JSON field names to index; other fields are stored but not searchable |
Response Body
| Field | Type | Description |
|---|---|---|
name | string | Collection name |
id_type | string | "number" or "string" |
searchable_fields | array of string | Searchable field names |
Response: 201 Created