Skip to main content
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.
  1. Sign up for a free Atlas account and deploy a cluster.
  2. In the Atlas UI, navigate to your cluster and select Connect to retrieve your connection string.
Example 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: To determine the right connection string format for your deployment type, see the MongoDB connection string documentation. Example local connection string:

Available integrations

Short-term and long-term memory

Use MongoDB as a persistent backend for agent memory:

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: MongoDBAtlasVectorSearch stores 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: MongoDBAtlasFullTextSearchRetriever and MongoDBAtlasHybridSearchRetriever support full-text and combined vector + keyword retrieval. See the MongoDB Atlas retriever guide.
  • Semantic cache: MongoDBAtlasSemanticCache retrieves cached LLM responses based on semantic similarity, backed by Atlas Vector Search.
See the MongoDB Atlas integrations page for imports and usage examples.