Chronicle
1.x
Docs/Chronicle/MongoDB Store
Open

Reading2 min
Updated31 Jul 2026
Sourcev1/stores/mongo.mdx

The store/mongo package implements Chronicle's store.Store interface using the grove ORM with the MongoDB driver. Events, streams, and compliance records are stored as documents, making it a natural fit for deployments that already run MongoDB.

Import01

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

Constructor02

db, err := grove.Open(mongodriver.Open("mongodb://localhost:27017", "chronicle"))
if err != nil {
    log.Fatal(err)
}

s := mongo.New(db)

Migrations03

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

Migrations create collections with JSON Schema validation (auto-generated from Grove model structs) and apply indexes on all Chronicle collections. They are idempotent -- safe to run on every startup.

Full setup with chronicle.New04

import (
    "context"
    "log"

    "github.com/xraph/grove"
    "github.com/xraph/grove/drivers/mongodriver"
    "github.com/xraph/chronicle"
    "github.com/xraph/chronicle/store"
    "github.com/xraph/chronicle/store/mongo"
)

ctx := context.Background()

db, err := grove.Open(mongodriver.Open("mongodb://localhost:27017", "chronicle"))
if err != nil {
    log.Fatal(err)
}

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

adapter := store.NewAdapter(s)

c, err := chronicle.New(chronicle.WithStore(adapter))

With the Forge extension05

import "github.com/xraph/chronicle/extension"

ext := extension.New(extension.WithStore(s))
app.Register(ext)

Interfaces implemented06

mongo.Store satisfies:

  • audit.Store

  • stream.Store

  • verify.Store

  • erasure.Store

  • retention.Store

  • compliance.ReportStore

  • store.Store (composite)

Characteristics07

AspectDetail
Drivergrove ORM + mongodriver
MigrationsGrove migrations with JSON Schema validation + indexes
TransactionsMongoDB sessions (replica-set required for multi-doc txns)
Collectionschronicle_events, chronicle_streams, chronicle_erasures, chronicle_retention_policies, chronicle_archives, chronicle_reports
Closedb.Close()

Grove Migrations08

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/chronicle/store/mongo"

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

When to use09

  • Document-oriented workloads where MongoDB is the primary data store.

  • Horizontally-scaled environments requiring sharding.

  • Teams already running MongoDB in their infrastructure.