Vault

MongoDB Store

Document store using Grove ORM with mongodriver for MongoDB.

The MongoDB store (store/mongo) provides a document-oriented backend using the Grove ORM with mongodriver. It maps Vault entities to 11 MongoDB collections with compound indexes for efficient tenant-scoped queries.

Usage

import (
    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/mongodriver"
    "github.com/xraph/vault/store/mongo"
)

// Open a MongoDB connection via Grove's mongodriver.
db := grove.Open(mongodriver.New(
    mongodriver.WithURI("mongodb://localhost:27017"),
    mongodriver.WithDatabase("vault"),
))

s := mongo.New(db)
if err := s.Migrate(ctx); err != nil {
    log.Fatal(err)
}

Options

OptionSignatureDescription
WithLoggerWithLogger(l *slog.Logger) StoreOptionSets the structured logger. Defaults to slog.Default().
s := mongo.New(db, mongo.WithLogger(slog.Default()))

Internals

AspectDetail
DriverGrove ORM with mongodriver (MongoDB)
MigrationsGrove migrations with JSON Schema validation + indexes
TransactionsIndividual operations are atomic; multi-document transactions require explicit sessions

Collections

CollectionEntity
vault_secretssecret.Secret
vault_secret_versionssecret.Version
vault_flagsflag.Definition
vault_flag_rulesflag.Rule
vault_flag_overridesflag.TenantOverride
vault_configconfig.Entry
vault_config_versionsconfig.EntryVersion
vault_overridesoverride.Override
vault_rotation_policiesrotation.Policy
vault_rotation_recordsrotation.Record
vault_auditaudit.Entry

Lifecycle methods

MethodBehaviour
Migrate(ctx)Creates collections with JSON Schema validation and indexes on all 11 collections
Ping(ctx)Calls db.Ping(ctx) to verify connectivity
Close()Calls db.Close() to disconnect from MongoDB

Grove Migrations

The store exports a Migrations group for use with Grove's migration orchestrator. This enables tracked, versioned migrations across all stores in your application:

import mongostore "github.com/xraph/vault/store/mongo"

// mongostore.Migrations is a migrate.Group for the vault mongo store.
// Register it with the grove migration orchestrator for coordinated migrations.

When to use

  • Document-oriented workloads -- flexible schemas that evolve with your application.
  • Horizontal scaling -- MongoDB sharding for large-scale deployments.
  • Cloud-native -- MongoDB Atlas for fully managed deployments.
  • Teams familiar with MongoDB -- leverage existing document database expertise.

On this page