MongoDB is a NoSQL, document-oriented database that supports JSON-like documents with a dynamic schema. You can run it as a self-managed deployment or as MongoDB Atlas, MongoDB’s fully managed cloud database.Install
langchain-mongodb for both self-managed and Atlas integration points. Run MongoDB on your own infrastructure, or use Atlas for a fully managed cloud experience. The document data model stores JSON-like documents with a flexible schema that adapts to your application.
Installation and setup
Install the Python package:Get your MongoDB connection string
You need a running MongoDB deployment and a connection string before integrating with LangChain. Choose the option that fits your environment.MongoDB Atlas
MongoDB Atlas is MongoDB’s fully managed cloud database, available on AWS, Azure, and GCP. It is the recommended option for production deployments and is required for Atlas-specific LangChain integrations such as vector search, full-text search, and hybrid search.- Sign up for a free Atlas account and deploy a cluster.
- In the Atlas UI, navigate to your cluster and select Connect to retrieve your connection string.
Self-managed MongoDB
MongoDB is available as a self-managed deployment for on-premises, private cloud, or local development environments. MongoDB offers two self-managed editions:- Community Edition: Free and open source. Suitable for local development and smaller deployments. Download Community Edition.
- Enterprise Advanced: For production on-premises deployments with advanced security and management features. Download Enterprise Advanced.
Available integrations
Short-term and long-term memory
Use MongoDB as a persistent backend for agent memory:- Short-term memory with MongoDB Atlas (
MongoDBSavercheckpointer) - Long-term memory with MongoDB Atlas (
MongoDBStore)
Model cache
MongoDBCache stores LLM responses in MongoDB without requiring a search index or an Atlas deployment. It works with both self-managed and Atlas deployments.
MongoDB Atlas integrations
The following integrations require MongoDB Atlas. You can use MongoDB Atlas with LangChain for vector search, retrieval, and semantic caching:- Vector store:
MongoDBAtlasVectorSearchstores embeddings in MongoDB and supports semantic search, filtered search, and hybrid search (vector + full-text via BM25). See the MongoDB Atlas vector store guide. - Retrievers:
MongoDBAtlasFullTextSearchRetrieverandMongoDBAtlasHybridSearchRetrieversupport full-text and combined vector + keyword retrieval. See the MongoDB Atlas retriever guide. - Semantic cache:
MongoDBAtlasSemanticCacheretrieves cached LLM responses based on semantic similarity, backed by Atlas Vector Search.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

