Skip to main content
OnDB uses collections to organize data, similar to tables in traditional databases. Indexes are required for production use.

Collections

Collections are logical groupings of documents:

Why Indexes Are Required

Every collection MUST have at least one index for production use.
Without indexes:

Index Types

Hash Index

Best for equality lookups (e.g., WHERE email = 'user@example.com'):

BTree Index

Best for range queries and sorting (e.g., WHERE createdAt > '2024-01-01'):

Price Index

Special type for value-based payment models. See PriceIndex for details.

When to Create Indexes

1

Before storing data

Create indexes BEFORE storing any data to ensure optimal performance from the start
2

Query fields

Index all fields used in whereField() queries
3

Foreign keys

Index foreign key fields used in relations and JOINs
4

Sort fields

Index fields used for sorting

Complete Example

Relations Between Collections

Create relations for better data organization:

Next Steps

Data Storage

Store data with payment callbacks

Querying

Query your indexed collections