Skip to content

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/collections

Response:

{
  "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/collections

Request 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/:id

Delete Collection

DELETE /api/v1/collections/:id
Danger: 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=20

Field Types

TypeDescriptionExampleIndexable
stringUTF-8 text"hello"Yes
number64-bit float42.5Yes
booleanTrue/falsetrueYes
datetimeISO 8601"2024-01-15T10:30:00Z"Yes
arrayOrdered list[1, 2, 3]No
objectNested JSON{"key": "value"}No