I am trying to create a db user from Python with pymongo. But I keep getting pymongo.errors.OperationFailure: CMD_NOT_ALLOWED: createUser error
client = MongoClient("mongodb+srv://username:[email protected]/admin")
db = client["testDB"]
db.command("createUser", "user", pwd="password")
am I missing something? Thanks.
Note: my db is on Mongo Atlas don't know if this changes anything.
I asked this problem to Atlas customer support and they gave me this answer hope it helps other people who tries the same thing. In short you cannot add user to Atlas with pymongo that is why it keeps giving error.
Hello, User management in MongoDB Atlas can only be accomplished by creating MongoDB Users in the following ways; via the Web UI or with the API All MongoDB users for Atlas are associated with the admin database; i.e. their authentication database is admin. The authentication database does not determine the user’s roles. Please note that the Admin database is for authentication purposes and is not meant to hold customer data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With