Collections API
Overview
Collections are the primary data containers in NexusDB. Each collection holds documents with a defined schema.
Endpoints
List Collections
GET /api/v1/collectionsResponse:
{
"collections": [
{
"id": "col_abc123",
"name": "users",
"document_count": 1542,
"size_bytes": 2048576,
"created_at": "2024-01-15T10:30:00Z"
}
],
"meta": { "total": 5, "page": 1 }
}Create Collection
POST /api/v1/collectionsRequest body:
{
"name": "products",
"schema": {
"fields": [
{ "name": "title", "type": "string", "required": true },
{ "name": "price", "type": "number" },
{ "name": "tags", "type": "array" },
{ "name": "metadata", "type": "object" }
]
},
"indexes": [
{ "fields": ["title"], "unique": true }
]
}Get Collection
GET /api/v1/collections/:idDelete Collection
DELETE /api/v1/collections/:idDanger: Deleting a collection permanently removes all documents. This cannot be undone.
Documents
Insert Document
POST /api/v1/collections/:id/documents{
"document": {
"title": "Wireless Keyboard",
"price": 79.99,
"tags": ["electronics", "peripherals"],
"metadata": { "sku": "KB-2024-001" }
}
}Query Documents
GET /api/v1/collections/:id/documents?where=price.gt.50&sort=-created_at&limit=20Field Types
| Type | Description | Example | Indexable |
|---|---|---|---|
string | UTF-8 text | "hello" | Yes |
number | 64-bit float | 42.5 | Yes |
boolean | True/false | true | Yes |
datetime | ISO 8601 | "2024-01-15T10:30:00Z" | Yes |
array | Ordered list | [1, 2, 3] | No |
object | Nested JSON | {"key": "value"} | No |