Skip to content

Conversation

@smartcoder0777
Copy link

@smartcoder0777 smartcoder0777 commented Jan 27, 2026

Fixes: #68659

What does this PR do?

Fixes the mongodb tops module to work with pymongo v4+ by replacing the deprecated mdb.authenticate() method with authentication credentials passed directly to the MongoClient constructor.

What issues does this PR fix or reference?

Fixes #68659

Previous Behavior

The mongodb tops module used the deprecated mdb.authenticate(user, password) method which was removed in pymongo v4. This caused authentication failures when using pymongo v4.9+ (required for MongoDB v8 compatibility).

conn = pymongo.MongoClient(host=host, port=port, ssl=ssl)
mdb = conn[database]
if user and password:
    mdb.authenticate(user, password)  # ❌ Removed in pymongo v4

New Behavior

Authentication credentials are now passed directly to MongoClient constructor using username, password, and authSource parameters, making it compatible with both pymongo v3 and v4+.

conn_kwargs = {"host": host, "port": port, "ssl": ssl}
if user and password:
    conn_kwargs["username"] = user
    conn_kwargs["password"] = password
    conn_kwargs["authSource"] = authdb  # Defaults to "admin"
conn = pymongo.MongoClient(**conn_kwargs)

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes

Contribution by Gittensor, see my contribution statistics at https://gittensor.io/miners/details?githubId=191128130

@smartcoder0777 smartcoder0777 requested a review from a team as a code owner January 27, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mongodb module not working with pymongo v4

1 participant