Schemas & Types

Data Types

TypeDescriptionExample
STRINGUTF-8 text'hello'
TEXTAlias for STRING'hello'
VARCHARAlias for STRING'hello'
INT64-bit signed integer42
FLOAT64-bit IEEE 7543.14
DECIMALArbitrary precision99.99
BOOLBooleantrue
TIMESTAMPUTC timestamp (nanosecond precision)now()
DATETIMEAlias for TIMESTAMP'2026-01-01T00:00Z'
UUID128-bit UUIDgen_uuid_v7()
GEOMETRYOGC geometry (WKB internally)ST_Point(-73.9, 40.7)
ARRAYOrdered listARRAY[1, 2, 3]
OBJECTNested document{ name: 'Alice' }

Schema Modes

Schemaless — No schema required. Fields can vary between documents. Types are inferred on insert. This is the default when you CREATE COLLECTION x.

Strict — Schema is defined at creation time and enforced on every write. O(1) field extraction via binary tuple format. Created with (...) WITH (engine='document_strict').

Typeguards (Schemaless Validation)

Typeguards add write-time validation to schemaless collections without changing the storage format. Guarded fields are type-checked; unguarded fields pass freely.

CREATE TYPEGUARD ON users (
    email STRING REQUIRED CHECK (email LIKE '%@%.%'),
    age INT CHECK (age >= 0 AND age <= 150),
    role STRING DEFAULT 'user',
    slug STRING VALUE LOWER(REPLACE(title, ' ', '-'))
);
ModifierBehavior
REQUIREDField must be present and non-null
DEFAULTInject a value when the field is absent or null
VALUEAlways inject/overwrite (computed fields)
CHECKSQL boolean expression validated at write time

Every write form enforces the guards: INSERT … VALUES, INSERT … { }, INSERT … SELECT, UPSERT, UPDATE, MERGE, and native puts, batches and updates.

RuleBehavior
Deterministic expressionsDEFAULT and VALUE are evaluated on every write. now(), uuid_v7() and nextval() are refused.
UPDATEVALUE recomputes. DEFAULT refills a field that is absent or set to null.
UPDATE validationREQUIRED and type are checked for the assigned and injected fields. CHECK runs whenever its field is present.
CRDT collectionsOnly REQUIRED, type and CHECK are accepted. Every replica merges the state, so nothing is injected. The guards judge the merged row each write produces.
-- Modify guards
ALTER TYPEGUARD ON users ADD score FLOAT CHECK (score >= 0);
ALTER TYPEGUARD ON users DROP age;

-- Audit existing data against guards
VALIDATE TYPEGUARD ON users;

-- Graduate to strict schema
CONVERT COLLECTION users TO document_strict;

CONVERT … TO document_strict carries each guard onto the converted schema:

Guard clauseConverted to
VALUE exprA GENERATED ALWAYS AS (expr) column
Constant DEFAULTA column DEFAULT
Cross-field DEFAULTRefused: a column DEFAULT is evaluated with no row in scope
CHECKA CHECK constraint

The converted schema keeps the source primary key. A column list that omits it is refused.

Schema Evolution (Strict Mode)

-- Add a column with a default (zero-downtime, multi-version reads)
ALTER COLLECTION orders ADD COLUMN region STRING DEFAULT 'us-east';

-- Drop a column
ALTER COLLECTION orders DROP COLUMN region;

ALTER ADD COLUMN uses multi-version reads — existing rows are served with the default value without rewriting storage. New writes include the column natively.

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