Skip to content

Authorization problem for unprivileged user on MongoDBDatabase init (list_collection_names issue) #225

@rafaelodon

Description

@rafaelodon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions