MongoDB vs. Firestore: Choosing an MCP Context Store
Pick MongoDB if you want a document store you can self-host, run in a container, or manage through Atlas with full control over connection credentials. Pick Firestore if you're already on Google Cloud and would rather authenticate through IAM than carry a password in a connection string. Both are two of open-context's 15 supported MCP context-store backends, both implement the exact same document-adapter interface, and — somewhat counterintuitively — Firestore's per-document size limit is actually smaller than MongoDB's, not larger.
Key takeaways
- MongoDB and Firestore both implement open-context's shared
DocumentDriverinterface — six methods (connect,close,ping,get,put,remove,list) also used by the Redis and DynamoDB backends. - MongoDB can be self-hosted, run in Docker, or used via Atlas; Firestore exists only as a Google Cloud service, authenticated through Application Default Credentials rather than a password in the connection string.
- MongoDB caps a single document at 16 mebibytes of BSON. Firestore's Native-mode limit — the mode open-context's driver uses — is 1 mebibyte per document, eight times smaller.
- Neither backend has a portable case-insensitive substring query, so
recall_contextandsearch_contextsread the whole collection and filter in memory on both — the same tradeoff Redis and DynamoDB make. - Switching between them, or to any of open-context's other 13 backends, is a single
opencontext db migratecommand that only reads the source store.
Same interface, two different kinds of database
MongoDB and Firestore both sit behind open-context's DocumentDriver interface, the
shared contract that also backs Redis and DynamoDB. Search, tag filtering, result ordering, and
cascading a bubble delete across its contexts are all written once in the document adapter — a
new backend only has to supply connect, close, ping,
get, put, remove, and list. That's why
save_context, recall_context, and the rest of open-context's MCP tools
behave identically whichever one is active.
But the two databases themselves start from very different assumptions. MongoDB is a general-purpose document database you can run anywhere — a laptop, a Docker container, your own server, or a managed Atlas cluster. Firestore is Google Cloud's native document database: there's no process to install, no port to open, just a project id and a client library that talks to Google's infrastructure directly.
How open-context talks to each one
The MongoDB driver stores contexts and bubbles in two collections, oc_contexts and
oc_bubbles, keyed by Mongo's own _id set to open-context's id — so a
lookup by id is a primary-key hit, not a scan. It also builds two indexes on connect,
bubbleId and createdAt, and sets ignoreUndefined: true on
the client so an absent bubbleId or description stays genuinely absent
instead of being written as BSON null — the one detail that keeps MongoDB's behavior
consistent with every other backend in the conformance suite.
The connection string itself gets normalized before it reaches the driver: open-context accepts
a mongo:// alias and any casing, but the Node MongoDB driver only accepts
mongodb:// or mongodb+srv://, case-sensitively, so a rewrite step
corrects the scheme while preserving +srv — dropping it would silently break an
Atlas connection by turning an SRV lookup into a direct connection to a host that doesn't answer.
The Firestore driver uses the same two-collection layout, but connects lazily — there's nothing to open eagerly, since the client library establishes its connection on first use. It authenticates through Google's Application Default Credentials chain, the same mechanism every other Google client library uses, so the connection string carries only a project id and never a secret.
Where they actually diverge
Document size: Firestore is the stricter one
This is the detail most people get backwards. MongoDB's BSON format caps a single document at
16 mebibytes
(MongoDB Manual: Documents) —
large enough that a saved context would have to be extraordinarily long to hit it. Firestore in
Native mode, which is what open-context's @google-cloud/firestore client talks to,
caps a single document at 1 mebibyte
(Google Cloud: Firestore quotas and limits).
Eight times smaller than MongoDB's, despite Firestore being the newer, fully managed option. A
very long pasted conversation saved as one context could fit comfortably on MongoDB and still get
rejected on Firestore.
Authentication: a secret in the URL vs. no secret at all
A MongoDB connection string is mongodb://user:pass@host:27017/db — the credential
lives right there, which is why open-context redacts it from every log line, API response, and UI
field before it's ever shown. Firestore's connection string is just firestore://PROJECT_ID;
there's no password to redact because there isn't one in the DSN. Authorization comes from whatever
service account or user credentials are already active in the environment via Application Default
Credentials — the right call when open-context already runs inside Google Cloud infrastructure that
has IAM configured, and a mismatch if it doesn't.
Where it can run
MongoDB has no cloud lock-in: run it in Docker for local development, on your own VM, or through Atlas, Azure Cosmos DB's Mongo API, or any other managed Mongo-compatible service. Firestore only exists as a Google Cloud service — there's no self-hosted Firestore, though Google does ship a local emulator for the client libraries if you want to test the driver without touching a live project.
Setting each one up
MongoDB needs a full connection string and its optional driver package:
export OPENCONTEXT_DB_URL="mongodb://user:pass@localhost:27017/opencontext"
npm i mongodb
Firestore needs only a project id — the database segment defaults to (default):
export OPENCONTEXT_DB_URL="firestore://my-gcp-project"
npm i @google-cloud/firestore
Both packages are optional peer dependencies, like every one of open-context's 15 backends — the default install and the Docker image stay small because nothing is pulled in until a DSN actually asks for that scheme.
What's identical no matter which you pick
Both backends are checked against the same roughly 50-test conformance suite covered in
Firestore vs. DynamoDB for a serverless store —
it's the only definition of correct behavior open-context has, and it never gets relaxed to make
a backend pass. Every list method on both backends returns results ordered by
createdAt ascending then id ascending, byte-identically to every SQL
backend. And both pay the same tax covered in
Redis vs. MongoDB for an MCP store:
neither has a portable case-insensitive substring predicate, so recall_context and
search_contexts read the whole collection into memory and filter there. The results
match a SQL backend exactly — just not as fast once the store gets large.
Which one to choose
| MongoDB | Firestore | |
|---|---|---|
| Where it runs | Anywhere — self-hosted, Docker, Atlas, Cosmos DB | Google Cloud only; no self-hosted option |
| Credentials | User/password in the connection string, redacted by open-context | Application Default Credentials chain — no secret in the DSN |
| Max document size | 16 MiB (BSON) | 1 MiB (Native mode) |
| Connection string | mongodb://user:pass@host:27017/db | firestore://my-project |
| Optional driver | mongodb | @google-cloud/firestore |
If you're already running infrastructure outside Google Cloud, or you want to keep full control over the database process and its credentials, MongoDB is the simpler fit. If open-context is already deployed on Google Cloud with IAM configured, Firestore removes a password from the picture entirely — just watch the 1 MiB document ceiling if you're saving long raw conversation exports as single contexts rather than chunking them.
Point open-context at MongoDB, Firestore, or any of its 15 backends.
Get started with open-context →FAQ
Does open-context require MongoDB or Firestore?
No. The default store is a local JSON file at ~/.opencontext/contexts.json and needs no setup at all. MongoDB and Firestore are two of 15 optional backends you point open-context at by setting OPENCONTEXT_DB_URL, useful once you already run one of them or need a shared, remote store.
Which has the larger document size limit, MongoDB or Firestore?
MongoDB, by a wide margin. A MongoDB document caps out at 16 mebibytes of BSON. Firestore's Native-mode limit, the mode open-context's driver uses, is 1 mebibyte per document — so a single saved context that's fine on MongoDB can be rejected on Firestore if it approaches that size.
Does open-context store database credentials for Firestore the way it does for MongoDB?
No. A MongoDB connection string carries a username and password, redacted before it's ever logged or shown in the UI. Firestore's connection string is just a project id — open-context authenticates through Google's Application Default Credentials chain instead, so no secret needs to live in OPENCONTEXT_DB_URL at all.
Can I run MongoDB or Firestore locally for testing?
MongoDB, yes — run it in a container and point OPENCONTEXT_DB_URL at mongodb://localhost:27017/opencontext. Firestore has no official self-hosted mode; it only exists as a Google Cloud service, though Google ships a local emulator for the Firestore client libraries if you need to test without touching a live project.
Can I switch from MongoDB to Firestore, or back, without losing data?
Yes. Run opencontext db migrate --to "<connection-string>" and it copies every context and bubble from whichever store is currently active into the new one. It only reads the source store, so nothing there is modified or deleted.