我正在尝试使用 pymongo 从 Python 创建一个 db 用户。但我不断收到 pymongo.errors.OperationFailure: CMD_NOT_ALLOWED: createUser 错误
client = MongoClient("mongodb+srv://username:password@mycluster-mogiz.mongodb.net/admin")
db = client["testDB"]
db.command("createUser", "user", pwd="password")
我错过了什么吗?谢谢。
注意:我的数据库在 Mongo Atlas 上,不知道这是否有任何改变。
最佳答案
我向 Atlas 客户支持提出了这个问题,他们给了我这个答案,希望它可以帮助其他尝试同样事情的人。简而言之,您无法使用 pymongo 将用户添加到 Atlas,这就是它不断给出错误的原因。
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.
关于python - 从python创建mongodb用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51498789/