python - 从python创建mongodb用户

标签 python mongodb pymongo

我正在尝试使用 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/

相关文章:

python - 使用Python修改电子邮件(email.Message)并添加附件

mongodb - sudo chown -R `id -u`/data/db 的含义

mongoDB 如何杀死/终止 map_reduce 作业?

python - 将数据帧列中的某些多个值重命名为另一个单个值

Python - 将德语变音符号音译为变音符号

python - 合并两个词典的部分以创建一个新词典

django - 使用 PyMongo 作为 Django 后端

node.js - 如何使用 Waterline Adapter for Mongo 在 Sails.js 中使用搜索修饰符 "OR"

mongodb - 如何评估 mongodb 分片集群冗余级别?

python - pymongo 在尝试连接到本地 Mongo 实例时返回 SSL 错误