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 |
---|---|---|---|
Error with MongoDB 7 on Ubuntu 22.04.4 LTS Deletes All Data | 0 | 616 | May 2024 |
Ubuntu20 Compilation Toolchain | 0 | 518 | May 2024 |
MongoDB Unattended install ignores INSTALLLOCATION. Installs in a new folder that somehow has my product name. | 0 | 440 | Jun 2024 |
wiredtiger checkpoint logging | 1 | 497 | Jul 2024 |
Discrepancy in Supported Platforms for MongoDB 8.0 | 0 | 63 | Jan 23 |