---
title: "Discussion on \"MongoDB vs PostgreSQL for a LangGraph RAG Agent: How to Choose\" | Hashnode"
description: "Discussion on \"MongoDB vs PostgreSQL for a LangGraph RAG Agent: How to Choose\". Separate the four storage jobs, then decide by data shape, transactions and what your team already runs."
url: "https://hashnode.com/posts/mongodb-vs-postgresql-for-a-langgraph-rag-agent-how-to-choose/6afd5556c50b19cb9ff6d2d2"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [MongoDB vs PostgreSQL for a LangGraph RAG Agent: How to Choose](https://boilershelf.hashnode.dev/mongodb-vs-postgresql-for-a-langgraph-rag-agent-how-to-choose?utm_source=hashnode&utm_medium=feed)

Separate the four storage jobs, then decide by data shape, transactions and what your team already runs.

Nov 18 · 5 min read · boilershelf.hashnode.dev  
Read the article

-   [#mongodb](https://hashnode.com/tag/mongodb)
-   [#postgresql](https://hashnode.com/tag/postgresql)
-   [#langgraph](https://hashnode.com/tag/langgraph)
-   [#rag](https://hashnode.com/tag/rag)
-   [#ai](https://hashnode.com/tag/ai)

## Written by

[BoilerShelf](https://hashnode.com/@boilershelf)

@boilershelf

  
[View profile](https://hashnode.com/@boilershelf)

Source code kits for RAG, document AI and AI SaaS.

BoilerShelf sells source code kits for RAG chatbots, document AI, AI agents and AI SaaS. One-time payment, full source code, commercial license.

## Responses 2

Markdown supported · ⌘↵ to post

[Adam Lewis](https://hashnode.com/@nark3d)

[Nov 24](https://hashnode.com/posts/mongodb-vs-postgresql-for-a-langgraph-rag-agent-how-to-choose/6afd5556c50b19cb9ff6d2d2/comment/6b055cc0f36224f426877890)

Both work, but the trade-off is in how much of the agent's state you want the database to understand. First, pin down what the checkpoints are for. If a checkpoint is just a way to resume a conversation and look back at a past run, then keeping old runs is all you're asking of it and either database handles that fine. If they're also how you replay a thread to debug or evaluate the agent, then the checkpoint is a queryable record and the schema around it matters a lot more than the choice of store. Which of those is the agent you're shipping meant to do?

[BoilerShelf](https://hashnode.com/@boilershelf)

[6d ago](https://hashnode.com/posts/mongodb-vs-postgresql-for-a-langgraph-rag-agent-how-to-choose/6afd5556c50b19cb9ff6d2d2/comment/6b055cc0f36224f426877890#reply-6b065cab09ba38af51bf5134)

Great framing, thanks Adam. That distinction is the real decision, and I should have made it explicit in the post.

If checkpoints are only for resuming threads, either store is fine and the main work is a retention policy, because every step writes one.

If you want to replay and evaluate runs, one caveat: the checkpointer serializes state for resuming, not for querying. Questions like "which threads called tool X and then failed" get awkward against raw checkpoints in either database. What has worked better is writing a small run/event record alongside the checkpoint (thread ID, step, node, tool calls, latency, outcome) with a schema you control. At that point PostgreSQL has the edge for me: you can join those records to users and documents and query them with plain SQL. MongoDB is still a good fit if your team lives in aggregation pipelines.

So resume-only, pick what your team runs. Replay and evals, design the run record first and let that choose the store.

Are you treating checkpoints as your eval source today, or logging traces separately?
