Weave

MongoDB Store

Document-oriented MetadataStore using Grove ORM with mongodriver for MongoDB.

The store/mongo package provides a MongoDB-backed MetadataStore using the Grove ORM with mongodriver. It stores collections, documents, and chunks in MongoDB collections with compound indexes for efficient tenant-scoped queries.

Installation

go get github.com/xraph/weave/store/mongo

Setup

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

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

store := mongostore.New(db)

Migrations

if err := store.Migrate(ctx); err != nil {
    log.Fatal("migrate:", err)
}

Creates compound and unique indexes on all three collections (weave_collections, weave_documents, weave_chunks) for efficient queries scoped by tenant and app.

Pairing with a vector store

Pair the MongoDB metadata store with a vector store for similarity search:

import (
    mongostore "github.com/xraph/weave/store/mongo"
    pgvec "github.com/xraph/weave/vectorstore/pgvector"
)

eng, err := engine.New(
    engine.WithStore(mongostore.New(db)),
    engine.WithVectorStore(pgvec.New(pool)),
    engine.WithEmbedder(emb),
)

Internals

AspectDetail
DriverGrove ORM with mongodriver (MongoDB)
MigrationsCreates compound and unique indexes via mongomigrate
TransactionsIndividual operations are atomic; multi-document transactions require explicit sessions

Collections

CollectionEntity
weave_collectionsCollection metadata -- name, model, chunk config, counters
weave_documentsDocument records -- state, hashes, source info
weave_chunksChunk text and byte offsets

All collections include tenant_id and app_id fields, and queries filter on them automatically.

Lifecycle

MethodBehaviour
Migrate(ctx)Creates indexes on all collections
Ping(ctx)Verifies database connectivity
Close()Disconnects from MongoDB

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