MongoDB
If your team already runs MongoDB, Recall can keep its memory there, on Atlas or your own servers. Every Recall capability works on it: typed facts, corrections, history, keyword search, cached reads, and agent resume, with agent writes committed in one transaction with their lease. No Atlas Search index is needed.
Before you start
- MongoDB 6.0 or later. A replica set is recommended, and Atlas always is one; a single-node replica set is enough (see Good to know).
- A user with
readWriteon the database Recall uses. recall0.21.0 or later:brew install polign/tap/recallorpip install polign-recall.
Run the memory server on MongoDB
-
Start MongoDB as a single-node replica set, if you are not using Atlas:
docker run -d --name mongo -p 27017:27017 mongo:8.0 --replSet rs0 --bind_ip_all docker exec mongo mongosh --eval 'rs.initiate({_id:"rs0",members:[{_id:0,host:"localhost:27017"}]})' -
Add Recall to Claude Code as an MCP server:
claude mcp add recall \ -e RECALL_BACKEND=mongodb \ -e MONGODB_URI='mongodb://localhost:27017/recall?directConnection=true' \ -- recall mcp -write
For Atlas, use the
mongodb+srv://connection string Atlas gives you; put the password inMONGODB_PASSWORDinstead of the string if you prefer. Add-agentfor the agent resume tools. Other MCP hosts take the same command and variables, or the flagsrecall -backend mongodb -url mongodb://... mcp -write. -
Restart Claude Code and ask it to remember something. The first write creates the collection.
recall setup and the Recall plugin set up
a polign_db connection. With MongoDB, add the MCP server yourself as in step 2.
Use it from Go
import (
"github.com/Polign/recall"
"github.com/Polign/recall/backend/mongodb"
)
backend, err := mongodb.New(mongodb.Config{
URL: os.Getenv("MONGODB_URI"),
})
defer backend.Close()
client, err := recall.NewClient(recall.Config{
Backend: backend,
Collection: "team_memory",
Registry: recall.DefaultRegistry(),
Embedder: recall.LexicalEmbedder{},
})
mongodb.Config also takes a Database (default: the connection
string's path, then recall) and a Client to share a
*mongo.Client you already have. The package uses the
official MongoDB Go driver,
which a program pulls in only by importing it.
What gets stored
| Recall | MongoDB |
|---|---|
| A collection | A collection named rc_ and the collection's name, created on the first write with the first vector's size |
| An event | A document: the event ID as _id, the vector, the metadata as JSON so it reads back exactly as written, and its scalar fields as {k, v} pairs for filtering |
| Indexes | A compound index on the metadata pairs, and a text index on the event text for keyword search |
| Bookkeeping | recall_collections maps each collection and counts its writes, which is what cached reads check; recall_leases holds agent leases |
Metadata is filtered through the pairs rather than as document fields, so Recall's field names, which can contain dots, never turn into MongoDB paths.
Agent resume and fenced writes
Leases are documents in recall_leases, taken and renewed in one atomic update
that judges expiry by the server's clock, so recall mcp -agent and
Client.Resume work as they do on polign_db. On a replica set, each agent write
commits in one transaction with a write to its lease document. A takeover that changes the
lease conflicts with the in-flight write, so a process that stalled past its lease cannot land
a late write over its successor's. See Resume for how
actions and leases fit together.
Good to know
- Vector search is exact: the similarity is computed in the server over the events a filter keeps, so the answer is the true nearest events with no search index to build. Agent memory collections hold thousands of events, where this is fast; it is not meant for collections of millions.
- On a standalone server, which has no transactions, an agent write is checked against its lease just before it lands rather than with it, and a listing and its total are two reads. Run a replica set for agents.
- A collection takes its vector size from the first write. Changing embedders needs a new collection.
- Keyword search uses MongoDB's
englishtext index, fixed when a collection is created.
If something goes wrong
| What you see | What to do |
|---|---|
unknown backend "mongodb" | Your recall is older than 0.21.0. Upgrade it. |
server selection error | MongoDB is not reachable at that address. For a local single-node replica set, add directConnection=true to the connection string. |
connection string must start with mongodb:// or mongodb+srv:// | Check MONGODB_URI. |
holds 256-dimensional vectors, not 384 | The collection was created with another embedder. Use a new -collection when you change embedders. |
lease_held on resume | Another process holds the agent, or one died less than a lease time ago. Wait for the lease to expire. |
Source & license
The MongoDB backend is part of Recall, open source under the Apache License 2.0, in github.com/Polign/recall. Bug reports and pull requests go there.