> ## Documentation Index
> Fetch the complete documentation index at: https://docs.langchain.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB integrations

> Integrate with MongoDB using LangChain Python.

> [MongoDB](https://www.mongodb.com/) 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](https://www.mongodb.com/docs/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:

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install langchain-mongodb
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-mongodb
  ```
</CodeGroup>

### 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](https://www.mongodb.com/cloud/atlas/register) and deploy a cluster.
2. In the Atlas UI, navigate to your cluster and select Connect to retrieve your connection string.

Example connection string:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
MONGODB_ATLAS_URI = "mongodb+srv://<username>:<password>@<cluster-url>/"
```

#### 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](https://www.mongodb.com/try/download/community).
* **Enterprise Advanced**: For production on-premises deployments with advanced security and management features. [Download Enterprise Advanced](https://www.mongodb.com/try/download/enterprise).

To determine the right connection string format for your deployment type, see the [MongoDB connection string documentation](https://www.mongodb.com/docs/manual/reference/connection-string/).

Example local connection string:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
MONGODB_URI = "mongodb://localhost:27017/"
```

## Available integrations

### Short-term and long-term memory

Use MongoDB as a persistent backend for agent memory:

* [Short-term memory with MongoDB Atlas](/oss/python/integrations/memory/mongodb-short-term-memory) (`MongoDBSaver` checkpointer)
* [Long-term memory with MongoDB Atlas](/oss/python/integrations/memory/mongodb-long-term-memory) (`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.

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_mongodb.cache import MongoDBCache
```

### 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](/oss/python/integrations/vectorstores/mongodb_atlas) guide.
* **Retrievers**: `MongoDBAtlasFullTextSearchRetriever` and `MongoDBAtlasHybridSearchRetriever` support full-text and combined vector + keyword retrieval. See the [MongoDB Atlas retriever](/oss/python/integrations/retrievers/mongodb_atlas) guide.
* **Semantic cache**: `MongoDBAtlasSemanticCache` retrieves cached LLM responses based on semantic similarity, backed by Atlas Vector Search.

See the [MongoDB Atlas integrations](/oss/python/integrations/providers/mongodb_atlas) page for imports and usage examples.

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/providers/mongodb.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
