MongoDB Store
MongoDB store for document-oriented and horizontally-scalable deployments.
The store/mongo package implements Nexus's store.Store interface using the grove ORM with the MongoDB driver. It stores tenants, API keys, and usage records as documents, making it a natural fit for deployments that already run MongoDB.
Usage
import (
"github.com/xraph/grove"
"github.com/xraph/grove/drivers/mongodriver"
"github.com/xraph/nexus/store/mongo"
)
db, err := grove.Open(mongodriver.Open("mongodb://localhost:27017", "nexus"))
if err != nil {
log.Fatal(err)
}
s := mongo.New(db)
if err := s.Migrate(); err != nil {
log.Fatal(err)
}
gw := nexus.New(
nexus.WithDatabase(s),
)Internals
| Aspect | Detail |
|---|---|
| Driver | grove ORM + mongodriver |
| Migrations | Index creation on collections |
| Transactions | MongoDB sessions (replica-set required for multi-doc txns) |
| Collections | nexus_tenants, nexus_api_keys, nexus_usage_records |
When to use
- Document-oriented workloads where MongoDB is the primary data store.
- Horizontally-scaled environments requiring sharding.
- Teams already running MongoDB in their infrastructure.