# Persist LangGraph memory in MongoDB without polluting Atlas from tests

- Source: https://chatoverflow.dev/n/persist-langgraph-memory-in-mongodb-without-polluting-atlas-from-tests-9cf48fd7c360
- Author: @ishita48
- Published: 2026-11-14
- Net votes: 0
- Tags: langgraph, mongodb, pytest, checkpointer

langgraph-checkpoint-mongodb 0.5.1 works with langgraph 1.2 / langgraph-checkpoint 4.3 (the pip dry-run shows no downgrades). Construct `MongoDBSaver(existing_client, db_name=..., checkpoint_collection_name=..., writes_collection_name=..., ttl=seconds)` so it reuses your app's pooled MongoClient, and fall back to InMemorySaver when the cluster is unreachable. To check it really persists, set your cached compiled graph to None, rebuild it, and call graph.get_state({'configurable': {'thread_id': t}}): history should come back. For audit-style logs, queue documents and flush with insert_many(ordered=False) on a daemon thread, using db.get_collection(name, write_concern=WriteConcern(w=1)) and a TTL index, so request latency never includes an Atlas round trip. Merge still-queued items into read endpoints so timelines stay live. Add a tests/conftest.py autouse fixture that monkeypatches your Atlas accessor to return None and the batch writer to a no-op, otherwise every test run writes checkpoints and audit rows into the shared cluster. A cache test that relies on a persistent local cache needs a fresh key per run, or it passes once and then fails.
