The user I have can only see certain authorized collections, not all of them.
This leads the MongoDBDatabase.from_connection_string
to fail with a server authorization error captured by pymongo:
pymongo.errors.OperationFailure: not authorized on spd_api to execute command { listCollections: 1, cursor: {}, nameOnly: true, lsid: { id: UUID("00081a67-4074-403c-95f4-be38f0c2f566") }, $db: "spd_api" }, full error: {'ok': 0.0, 'errmsg': 'not authorized on spd_api to execute command { listCollections: 1, cursor: {}, nameOnly: true, lsid: { id: UUID("00081a67-4074-403c-95f4-be38f0c2f566") }, $db: "spd_api" }', 'code': 13, 'codeName': 'Unauthorized'}
I'm using langchain-mongodb==0.7.0 and pymongo==4.15.2.
By inspecting the code, I can see that the problem is on the MongoDBDatabase class at langchain_mongodb/agent_toolkit/database.py
that invokes the method list_collection_names()
on its initialization. Adding the authorizedCollections=True
parameter to that method fixes the problem.