Collections

A collection is NodeDB's top-level data container — analogous to a table in PostgreSQL or a collection in MongoDB. Each collection has a storage engine chosen at creation time.

Creating Collections

-- Schemaless document (default)
CREATE COLLECTION users;

-- Strict document (schema-enforced)
CREATE COLLECTION orders TYPE DOCUMENT STRICT (
    id UUID DEFAULT gen_uuid_v7(),
    customer_id UUID NOT NULL,
    total DECIMAL NOT NULL,
    status STRING DEFAULT 'pending'
);

-- Columnar (analytics)
CREATE COLLECTION events TYPE COLUMNAR (
    ts TIMESTAMP TIME_KEY,
    user_id UUID,
    event VARCHAR,
    duration_ms INT
);

-- Key-Value
CREATE COLLECTION sessions TYPE KEY_VALUE (key TEXT PRIMARY KEY);

Storage Engines

TypeDDLBest for
DocumentCREATE COLLECTION xFlexible data, prototyping, agent state
Document (strict)TYPE DOCUMENT STRICTOLTP, transactions, known schemas
ColumnarTYPE COLUMNARAnalytics, reporting, scan-heavy workloads
Key-ValueTYPE KEY_VALUESessions, caches, counters, key-dominant access

Columnar collections can specialize via profiles:

ProfileColumn ModifierExtra capabilities
Plain(none)Full UPDATE/DELETE, general analytics
TimeseriesTIME_KEYRetention, continuous aggregation, ILP ingest
SpatialSPATIAL_INDEXR*-tree indexing, OGC predicates

Cross-Engine Indexes

Any collection can have indexes from multiple engines:

CREATE COLLECTION products;

-- Add a vector index for semantic search
CREATE VECTOR INDEX ON products METRIC cosine DIM 384;

-- Add a full-text index for keyword search
CREATE SEARCH INDEX ON products FIELDS title, description ANALYZER 'english';

-- Add a spatial index for location queries
CREATE SPATIAL INDEX ON products FIELDS location;

-- Add graph edges for relationships
GRAPH INSERT EDGE FROM 'products:p1' TO 'products:p2' TYPE 'similar';

Converting Between Engines

Collections can be converted at any time without data loss:

CONVERT COLLECTION users TO strict;
CONVERT COLLECTION logs TO columnar;
CONVERT COLLECTION cache TO kv;
CONVERT COLLECTION events TO document;

NodeDB infers the schema from existing documents when converting to strict mode.

View page sourceLast updated on Apr 18, 2026 by Farhan Syah