Indexes

Index Types

TypeCommandUse Case
Single-fieldcreate_index("users", "email")Fast equality and range lookups
Uniquecreate_unique_index("users", "email")Enforce uniqueness
Compositecreate_composite_index("users", ["dept", "age"])Multi-field queries, compound sort
Textcreate_text_index("articles", ["title", "body"])Full-text search
Vectorcreate_vector_index("items", "embedding", 384, "cosine")Similarity search

Index Optimizations

  • Index-only count -- count() returns the index set size without touching documents. Up to 446x faster than scanning.
  • Index-backed sort -- When the sort field is indexed, retrieval is O(limit) instead of O(n log n).
  • Composite prefix scan -- Index on [A, B, C] can answer queries on A, or A+B, or A+B+C.
  • Early termination -- find_one and delete_one stop after the first match.
  • Zero-decode -- Fully indexed queries skip document deserialization entirely.