Find the fast path.
Create indexes for real query patterns, uniqueness and text search.
Create a useful index
const users = BsonLite.collection('users');
await users.createIndex({ email: 1 }, { unique: true });
await users.createIndex({ active: 1, createdAt: -1 });
const indexes = await users.listIndexes().toArray();A unique index rejects duplicate indexed values. Existing duplicates can prevent index creation. Compound field order matters: choose indexes for your filters and sort order, then validate with real data.
Text search
const notes = BsonLite.collection('notes');
await notes.createIndex({ title: 'text', body: 'text' });
const matches = await notes.find({
$text: { $search: 'portable database' }
}).toArray();Text search uses the server capabilities and language behavior of MongoDB 4.0. It requires a text index. It is different from Atlas Search, which this local SDK does not provide.
Keep index costs visible
- Each index consumes disk space and adds work to writes.
- Index construction can take time on existing collections.
- Use supported MongoDB 4.0 index options. Native encryption is enforced after collection/index storage settings.
- Drop an index only after checking the application queries that rely on it.
// Example: drop an intentionally retired non-_id index.
await users.dropIndex('active_1_createdAt_-1');Documentation for BsonLite 0.6.0-rc.1. View SDK source · Download the validated SDK