Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create mongodb user from python

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.

like image 771
Mustafa Yılmaz Avatar asked Oct 29 '25 07:10

Mustafa Yılmaz


1 Answers

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.

like image 170
Mustafa Yılmaz Avatar answered Oct 31 '25 12:10

Mustafa Yılmaz