langchain - ✅(Solved) Fix MongoDB Toolkit fails with Firestore MongoDB-compatible endpoint due to unsupported authorizedCollections option [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36609Fetched 2026-04-09 07:50:58
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
0
Participants
Timeline (top)
labeled ×3cross-referenced ×2issue_type_added ×1

Issue

MongoDB Toolkit fails when used with a Firestore MongoDB-compatible endpoint because the authorizedCollections option is not supported.

Description

When initializing MongoDBDatabase, LangChain internally executes a listCollections command via PyMongo. The MongoDB driver includes the option authorizedCollections=true.

Firestore's MongoDB-compatible endpoint rejects this option and returns the following error:

pymongo.errors.OperationFailure: authorizedCollections is not supported
full error: {
  'ok': 0.0,
  'errmsg': 'authorizedCollections is not supported',
  'code': 2,
  'codeName': 'InvalidArgument'
}

Because of this, MongoDBDatabase initialization fails and the MongoDB Toolkit cannot be used with the Firestore MongoDB-compatible endpoint.

Behavior Observed The MongoDB Toolkit works correctly when connecting to a standard MongoDB instance. When connecting to a Firestore MongoDB-compatible endpoint, initialization fails due to the unsupported authorizedCollections parameter.

What I Tested Tested in a local environment -> same error Deployed in Google Cloud Run -> same error

Since the error occurs in both environments, it appears to be related to compatibility with Firestore’s MongoDB-compatible layer rather than a networking issue.

Expected Behavior

One of the following would help:

  • MongoDB Toolkit should gracefully handle MongoDB-compatible endpoints that do not support authorizedCollections, or
  • Documentation should clarify that the MongoDB Toolkit only supports full MongoDB deployments.

Additional Context

Firestore provides a MongoDB-compatible API but does not implement the full MongoDB command set. I could not find documentation indicating whether LangChain MongoDB Toolkit supports this compatibility layer.

Environment

  • LangChain version: 1.2.15
  • langchain-mongodb version: 0.11.0
  • PyMongo version: 4.16.0
  • Python version: 3.13

Deployment:

Local machine Google Cloud Run

Database: Firestore MongoDB-compatible endpoint

Error Message

pymongo.errors.OperationFailure: authorizedCollections is not supported full error: { 'ok': 0.0, 'errmsg': 'authorizedCollections is not supported', 'code': 2, 'codeName': 'InvalidArgument' }

Root Cause

MongoDB Toolkit fails when used with a Firestore MongoDB-compatible endpoint because the authorizedCollections option is not supported.

Fix Action

Fix / Workaround

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

PR fix notes

PR #363: fix: handle Firestore MongoDB-compatible endpoint that lacks authorizedCollections

Description (problem / solution / changelog)

Summary

Fixes MongoDBDatabase initialization failure when connecting to Firestore's MongoDB-compatible endpoint.

Problem: Firestore's MongoDB-compatible endpoint does not support the authorizedCollections parameter in the listCollections command, causing:

pymongo.errors.OperationFailure: authorizedCollections is not supported

Solution: Catch the PyMongoError when calling list_collections_names(authorizedCollections=True) fails, and fall back to calling it without the parameter.

Code Change:

# Try with authorizedCollections=True first, fall back to False
# for MongoDB-compatible endpoints (e.g., Firestore) that don't support it
try:
    self._all_colls = set(
        self._db.list_collection_names(authorizedCollections=True)
    )
except PyMongoError:
    self._all_colls = set(self._db.list_collection_names())

Fixes langchain-ai/langchain#36609

Changed files

  • libs/langchain-mongodb/langchain_mongodb/agent_toolkit/database.py (modified, +8/-3)

PR #365: fix: handle authorizedCollections=True for Firestore MongoDB compatibility

Description (problem / solution / changelog)

Summary

Firestore and other non-native MongoDB backends do not support the authorizedCollections parameter in list_collection_names(), causing an OperationFailure at initialization.

This wraps all three call sites (database.py, cache.py, graphrag/graph.py) in try/except so they gracefully degrade to the parameter-less version when a PyMongoError is raised.

Fixes langchain-ai/langchain#36609

Changes

  • agent_toolkit/database.py: wrap list_collection_names(authorizedCollections=True) in try/except
  • cache.py: same fix for MongoDBCache initialization
  • graphrag/graph.py: same fix for graph collection initialization

Testing

Existing tests should pass. The try/except path only activates when authorizedCollections is rejected by the server, which is the exact scenario described in the issue.

Changed files

  • libs/langchain-mongodb/langchain_mongodb/agent_toolkit/database.py (modified, +6/-3)
  • libs/langchain-mongodb/langchain_mongodb/cache.py (modified, +8/-3)
  • libs/langchain-mongodb/langchain_mongodb/graphrag/graph.py (modified, +8/-4)

Code Example

from langchain_mongodb.agent_toolkit import MongoDBDatabase, MongoDBDatabaseToolkit 
# Connection configuration 
MONGO_URI = "mongodb://<USERNAME>:<PASSWORD>@<PROJECT_ID>.us-central1.firestore.goog:443/?loadBalanced=true&tls=true&authMechanism=SCRAM-SHA-256&retryWrites=false" 
DB_NAME = "<DATABASE_NAME>" 
# Initialize MongoDB database 
db = MongoDBDatabase.from_connection_string( MONGO_URI, database=DB_NAME, ) 
# Initialize toolkit 
toolkit = MongoDBDatabaseToolkit( db=db, llm=llm, ) 
tools = toolkit.get_tools()

---

pymongo.errors.OperationFailure: authorizedCollections is not supported
full error: {
  'ok': 0.0,
  'errmsg': 'authorizedCollections is not supported',
  'code': 2,
  'codeName': 'InvalidArgument'
}

---

pymongo.errors.OperationFailure: authorizedCollections is not supported
full error: {
  'ok': 0.0,
  'errmsg': 'authorizedCollections is not supported',
  'code': 2,
  'codeName': 'InvalidArgument'
}
RAW_BUFFERClick to expand / collapse

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-openrouter
  • langchain-perplexity
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Related Issues / PRs

Reproduction Steps / Example Code (Python)

from langchain_mongodb.agent_toolkit import MongoDBDatabase, MongoDBDatabaseToolkit 
# Connection configuration 
MONGO_URI = "mongodb://<USERNAME>:<PASSWORD>@<PROJECT_ID>.us-central1.firestore.goog:443/?loadBalanced=true&tls=true&authMechanism=SCRAM-SHA-256&retryWrites=false" 
DB_NAME = "<DATABASE_NAME>" 
# Initialize MongoDB database 
db = MongoDBDatabase.from_connection_string( MONGO_URI, database=DB_NAME, ) 
# Initialize toolkit 
toolkit = MongoDBDatabaseToolkit( db=db, llm=llm, ) 
tools = toolkit.get_tools()

Error Message and Stack Trace (if applicable)

pymongo.errors.OperationFailure: authorizedCollections is not supported
full error: {
  'ok': 0.0,
  'errmsg': 'authorizedCollections is not supported',
  'code': 2,
  'codeName': 'InvalidArgument'
}

Description

Issue

MongoDB Toolkit fails when used with a Firestore MongoDB-compatible endpoint because the authorizedCollections option is not supported.

Description

When initializing MongoDBDatabase, LangChain internally executes a listCollections command via PyMongo. The MongoDB driver includes the option authorizedCollections=true.

Firestore's MongoDB-compatible endpoint rejects this option and returns the following error:

pymongo.errors.OperationFailure: authorizedCollections is not supported
full error: {
  'ok': 0.0,
  'errmsg': 'authorizedCollections is not supported',
  'code': 2,
  'codeName': 'InvalidArgument'
}

Because of this, MongoDBDatabase initialization fails and the MongoDB Toolkit cannot be used with the Firestore MongoDB-compatible endpoint.

Behavior Observed The MongoDB Toolkit works correctly when connecting to a standard MongoDB instance. When connecting to a Firestore MongoDB-compatible endpoint, initialization fails due to the unsupported authorizedCollections parameter.

What I Tested Tested in a local environment -> same error Deployed in Google Cloud Run -> same error

Since the error occurs in both environments, it appears to be related to compatibility with Firestore’s MongoDB-compatible layer rather than a networking issue.

Expected Behavior

One of the following would help:

  • MongoDB Toolkit should gracefully handle MongoDB-compatible endpoints that do not support authorizedCollections, or
  • Documentation should clarify that the MongoDB Toolkit only supports full MongoDB deployments.

Additional Context

Firestore provides a MongoDB-compatible API but does not implement the full MongoDB command set. I could not find documentation indicating whether LangChain MongoDB Toolkit supports this compatibility layer.

Environment

  • LangChain version: 1.2.15
  • langchain-mongodb version: 0.11.0
  • PyMongo version: 4.16.0
  • Python version: 3.13

Deployment:

Local machine Google Cloud Run

Database: Firestore MongoDB-compatible endpoint

System Info

System Information

OS: Linux OS Version: #106~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Mar 6 08:44:59 UTC Python Version: 3.10.12 (main, Mar 3 2026, 11:56:32) [GCC 11.4.0]

extent analysis

TL;DR

The MongoDB Toolkit in LangChain fails to initialize when used with a Firestore MongoDB-compatible endpoint due to the unsupported authorizedCollections option.

Guidance

  • The error occurs because the authorizedCollections option is not supported by Firestore's MongoDB-compatible endpoint.
  • To fix this issue, the LangChain MongoDB Toolkit needs to be modified to handle this compatibility issue, either by removing the authorizedCollections option or by adding a check to see if the endpoint supports it.
  • The PyMongo library used by LangChain includes this option by default, so a potential workaround could be to find a way to disable this option when connecting to a Firestore MongoDB-compatible endpoint.
  • Another possible solution is to update the documentation to clarify that the MongoDB Toolkit only supports full MongoDB deployments and not MongoDB-compatible endpoints like Firestore.

Example

No code example is provided as the fix would require modifying the LangChain library or the PyMongo library, which is not a straightforward task.

Notes

The issue seems to be related to the compatibility of the LangChain MongoDB Toolkit with Firestore's MongoDB-compatible endpoint. The error message clearly indicates that the authorizedCollections option is not supported, which suggests that the fix should be related to handling this option.

Recommendation

Apply workaround: The best course of action would be to find a way to disable the authorizedCollections option when connecting to a Firestore MongoDB-compatible endpoint, as updating the library or the documentation might not be feasible or immediate.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING