Collections

A collection is a group of related documents — like a table in SQL, or a model in an ORM.

Each collection is defined by a schema that describes the shape of the data it holds.

📦 Defining a Collection

You define collections inside the schema object when initializing your client:

const db = createClient({
  apiKey: "your_api_key",
  schema: {
    users: {
      properties: {
        name: { type: "string", required: true },
        email: { type: "string", required: true, unique: true },
        isAdmin: { type: "boolean", default: false },
      },
    },
  },
});

This creates a users collection with three fields:

  • name (required string)
  • email (required string, unique)
  • isAdmin (optional boolean with a default)

✅ Schema-based, not schema-less

Unlike traditional NoSQL databases, NotDatabase enforces your schema. That means:

  • You get validation out of the box
  • Required fields must be present
  • Unique fields are checked on insert

You don't need to write validation logic — it's all automatic.

🔗 One Schema per Collection

Each collection has a single schema. If you update the schema, it applies to all documents going forward (past documents are untouched unless updated).

🔐 Unique & Required Fields

You can define fields as required or unique:

email: { type: "string", required: true, unique: true }

NotDatabase will:

  • Block inserts if email is missing
  • Prevent duplicates if email already exists