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 |
---|---|---|---|
Planning MongoDB Replica Set upgrade 4.4.18 to 6.0.15 | 1 | 690 | May 2024 |
Permission error on mongodb-atlas-local with volume | 5 | 1.4k | Aug 2024 |
MongoDB 2.6.11 on CentOS 6.5 to MongoDB 6.0.15 upgrade | 0 | 389 | Jun 2024 |
How to upgrade MongoDB community edition on Windows Server | 1 | 247 | Aug 2024 |
configuration details. E: Failed to fetch https://repo.mongodb.org/apt/ubuntu/dists/focal/mongodb-org/8.0/InRelease 403 Forbidden | 0 | 63 | Nov 2024 |