Shield

MongoDB Store

MongoDB store for document-oriented and horizontally-scalable deployments.

The store/mongo package implements Shield's store.Store interface using the grove ORM with the MongoDB driver. It stores all Shield subsystem data as documents with automatic index creation, making it a natural fit for deployments that already run MongoDB.

Usage

import (
    "context"
    "log"

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

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

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

Collections

CollectionSubsystemPurpose
shield_instinctsinstinctBuilt-in safety rules and threat patterns
shield_awarenessawarenessContext-aware detection configurations
shield_boundariesboundaryInput/output boundary enforcement rules
shield_valuesvaluesValue-alignment rule definitions
shield_judgmentsjudgmentContent evaluation and scoring rules
shield_reflexesreflexAutomatic response and action triggers
shield_profilesprofileComposite safety profile configurations
shield_scansscanContent scan results and audit log
shield_policiespolicyOrganizational safety policy definitions
shield_pii_tokenspiiTokenized PII storage for redaction/recovery
shield_compliance_reportscomplianceGenerated compliance audit reports

Internals

AspectDetail
Drivergrove ORM + mongodriver
MigrationsGrove migrations with JSON Schema validation + indexes
TransactionsMongoDB sessions (replica-set required for multi-doc txns)
ConcurrencyDocument-level locking with horizontal scalability

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

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

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.

On this page