Cindel indexes control how the code generator createsDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/mainser/cindel/llms.txt
Use this file to discover all available pages before exploring further.
where() query helpers for your collections and how the underlying backend organizes data for fast lookups. Adding @Index to a field tells the generator to emit typed equality and range helpers for that field; choosing the right index type further shapes which query operations are available and how much storage space the index uses at write time.
Single-Field Indexes with @Index
Annotate any collection field with @Index() to mark it as indexed. The generator produces where() helpers bound to that field, and the backend stores an ordered index entry for every document write:
where() helpers use the index for efficient lookups rather than a full collection scan:
Uniqueness
Passunique: true to require that no two documents share the same indexed value. Cindel enforces the constraint at write time and rejects inserts or updates that would create a duplicate:
Unique-Replace Upserts
Combiningunique: true with replace: true tells the generator to emit a named putByFieldName helper. When you call the helper, Cindel checks whether a document already holds that value and, if one exists, reuses its id instead of inserting a duplicate:
Case-Insensitive Lookups
For string fields,caseSensitive: false stores a lowercased form of the value in the index. Equality and range lookups against that index are then case-insensitive:
Index Types
Thetype parameter of @Index selects the storage and query strategy for a field. The default is CindelIndexType.value.
CindelIndexType.value (default)
Stores the original sortable value in the index. Supports both equality helpers (equalTo, notEqualTo) and range helpers (greaterThan, lessThan, between). Use this type for any field you want to query with ranges or sort through where():
CindelIndexType.hash
Stores a compact, stable hash of the indexed value instead of the value itself. Hash indexes use less space and are suitable for long strings where you only ever need equality lookups. Range queries are not available on hash indexes:
CindelIndexType.words
Splits a string field into individual word tokens and stores one index entry per token. The generator emits token-lookup and token-prefix helpers. Use this type for full-text style word searches:
CindelIndexType.multiEntry
Stores one index entry for each element of a primitive list field. The generator emits list-membership helpers so you can find all documents that contain a given element:
Complete Field-Index Example
TheArticle model below combines all four index types:
title— value index; supports equality and range helpersnormalizedTitle— value index with case folding; lookup is case-insensitivebody— word-token index; supports per-word and word-prefix lookupstags— multi-entry index; one entry per tag, supports element-equality helpers
Composite Indexes with CompositeIndex
Composite indexes span two or more fields and are declared on the collection itself using the indexes parameter of @Collection. They generate where() helpers that accept values for all participating fields together:
CompositeIndex must match the Dart field names (or the @Name override if present). The order of the list determines the index sort order: the backend sorts by accountId first, then by createdAt.
Composite Index Options
CompositeIndex accepts the same unique, replace, and caseSensitive options as @Index:
unique: true— enforces uniqueness across the full composite keyreplace: true— generates aputBy<IndexName>upsert helper that reuses an existing id when the composite key already existscaseSensitive: false— folds string values in the composite key before comparison
Add
@Index only to fields you actively query through where() or that are required for uniqueness enforcement. Every indexed field adds a write-time overhead because the backend must keep the index entries up to date on every insert and update. Fields used only in filter() expressions do not need an index — filter() operates over already-retrieved documents.