I am using MongoSH and PyMongo within Visual Code on WSL. I have successfully accessed the cluster from MongoSH, but PyMongo seems to be successfully accessing some cluster but one that doesn’t have my username.
For the following code in PyMongo:
print(db.command({ ‘connectionStatus’: 1 }))
The response is:
{‘authInfo’: {‘authenticatedUsers’: , ‘authenticatedUserRoles’: }, ‘ok’: 1.0},
but for
db.runCommand({ connectionStatus: 1 }) in MongoSH, I get
{
authInfo: {
authenticatedUsers: [ { user: ‘natanmelzer’, db: ‘admin’ } ],
authenticatedUserRoles: [ { role: ‘readWriteAnyDatabase’, db: ‘admin’ } ]
},
ok: 1
}
How is this possible, and how can I fix it?
Skip to main content
after
client=MongoClient('mongodb+srv://yourname:yourpassword@yourcluster.mongodb.net'
(or however you get your MongoClient instance)
db=client.foo
print(db.command({'connectionStatus': 1}))
works for me.
This helped me snap out of trying to run PyMongo using the Shell, and got me to just use the connection string in PyMongo, which I should have done all along.
Thank you so much! Let me try it!
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
Install instructions failing with signature warning | 1 | 676 | May 2024 |
MongoDB log is flooded with SSL error warnings | 0 | 331 | Jul 2024 |
Oplog tailing significantly faster after upgrade | 0 | 183 | Aug 2024 |
Defining custom write concern is at MongoDB 5 is not working as expected | 0 | 34 | Sep 2024 |
Service failed to start during installation for 8.0.x | 1 | 81 | Jan 2 |