MongoDB Adapter
The @bolkauth/adapter-mongodb package provides native MongoDB integration for BolkAuth using the official mongodb driver. It features cached collection references, atomic findOneAndUpdate operations, and secondary B-Tree indexing on userId columns.
Installation
Quick Start
Initialize BolkAuth with the MongoDB adapter by passing a connected Db instance from the official mongodb package:
Secondary Indexing (ensureIndexes)
MongoDB collections performance relies on secondary B-Tree indexes for fast session lookup by token and user lookup by email/ID.
Call ensureIndexes(db) during app initialization:
This creates the following compound & unique indexes across collections:
bolkauth_users: unique index onemailbolkauth_sessions: unique index onsession_token, index onuser_idbolkauth_accounts: unique compound index on{ provider, provider_account_id }, index onuser_idbolkauth_verification_tokens: unique compound index on{ identifier, token }bolkauth_user_metadata: index onuser_id
Zero-Boilerplate MongoDB Driver
For automatic connection pooling, environment index creation flags, and clean lifecycle management, use @bolkauth/driver-mongodb: