Ctrl Plane

MongoDB Store

Document store using Grove ORM with mongodriver for MongoDB.

The MongoDB store (store/mongo) uses the Grove ORM with mongodriver to persist data in MongoDB. It is the recommended store for teams that prefer document databases or need horizontal scalability.

When to use

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

Configuration

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

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

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

With the app

cp, err := app.New(
    app.WithStore(s),
)

Collections

The MongoDB store uses 15 collections:

CollectionEntityPrimary key
cp_instancesInstanceTypeID string
cp_deploymentsDeploymentTypeID string
cp_releasesReleaseTypeID string
cp_health_checksHealthCheckTypeID string
cp_health_resultsHealthResultTypeID string
cp_metricsMetricTypeID string
cp_logsLogEntryTypeID string
cp_tracesTraceTypeID string
cp_resource_snapshotsResourceSnapshotTypeID string
cp_domainsDomainTypeID string
cp_routesRouteTypeID string
cp_certificatesCertificateTypeID string
cp_secretsSecretTypeID string
cp_tenantsTenantTypeID string
cp_audit_entriesAuditEntryTypeID string

Internals

AspectDetail
DriverGrove ORM with mongodriver (MongoDB)
SerializationIntermediate BSON model structs with bson: tags
IdentityTypeID strings stored as _id field
MigrateCreates compound and unique indexes on all collections
Pingdb.Ping(ctx)
Closedb.Close() to disconnect

Indexes

Migrate() creates compound indexes for efficient queries:

  • All collections -- (tenant_id, ...) compound indexes for tenant-scoped queries.
  • Instances -- unique (tenant_id, slug) index.
  • Tenants -- unique (slug) index.
  • Domains -- unique (hostname) index.
  • Secrets -- unique (tenant_id, instance_id, key) index.
  • Time-series -- (tenant_id, instance_id, timestamp) for metrics, logs, traces, and snapshots.

Limitations

  • External dependency -- requires a running MongoDB instance or Atlas cluster.
  • No ACID transactions -- individual operations are atomic, but multi-document transactions require explicit sessions.
  • Index management -- Migrate() must run before first use to create indexes.

Comparison

FeatureMemoryBadgerPostgreSQLSQLiteMongoDB
SetupNonePath onlyDSNFile pathURI
PersistenceNoYesYesYesYes
Multi-processNoNoYesNoYes
Query flexibilityLowLowHighMediumHigh
Horizontal scalingNoNoRead replicasNoSharding
Best forTestsEmbedded KVProduction SQLEmbedded SQLProduction NoSQL

On this page