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
| Collection | Subsystem | Purpose |
|---|---|---|
shield_instincts | instinct | Built-in safety rules and threat patterns |
shield_awareness | awareness | Context-aware detection configurations |
shield_boundaries | boundary | Input/output boundary enforcement rules |
shield_values | values | Value-alignment rule definitions |
shield_judgments | judgment | Content evaluation and scoring rules |
shield_reflexes | reflex | Automatic response and action triggers |
shield_profiles | profile | Composite safety profile configurations |
shield_scans | scan | Content scan results and audit log |
shield_policies | policy | Organizational safety policy definitions |
shield_pii_tokens | pii | Tokenized PII storage for redaction/recovery |
shield_compliance_reports | compliance | Generated compliance audit reports |
Internals
| Aspect | Detail |
|---|---|
| Driver | grove ORM + mongodriver |
| Migrations | Index creation on collections |
| Transactions | MongoDB sessions (replica-set required for multi-doc txns) |
| Concurrency | Document-level locking with horizontal scalability |
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.