在 Mongodb ad C# 驱动程序上创建用户

Create User on Mongodb ad C# driver

提问人:Salvatore Lorello 提问时间:5/31/2021 最后编辑:Wernfried DomscheitSalvatore Lorello 更新时间:5/31/2021 访问量:117

问:

嗨,大家好,我想问一下创建对特定数据库具有读写权限的新用户的最佳方法是什么。 我正在尝试这个,但它不起作用

var command = new BsonDocument
            {
                {"createUser", Mail.Text },
                {"pwd", Password.Text },
                {"roles", new BsonArray()
                    {
                        new BsonDocument
                        {
                            {"role", "readWrite"},
                            {"db", DenSociale.Text }
                        }
                    } 
                }
            };
            await db.RunCommandAsync<BsonDocument>(command);

返回此错误

MongoError: 未授权 (User) 执行命令 { createUser: “newuser”, pwd: “xxx”, roles: [ { role: “readWrite”, db: “User” } ], lsid: { id: UUID(“ce6c39d4-e14c-4f6c-b5d0-d66d210e9833”) }, $clusterTime: { clusterTime: Timestamp(1622456008, 30), signature: { hash: BinData(0, F02EF0CAD605D9ECBCF3E928F84853FECE9B2829), keyId: 6968352101504122883 } }, $db: “(User)” }

C# 数据库 MongoDB

评论

0赞 ProgrammingLlama 5/31/2021
请只为您的问题添加相关标签。是的,你可能正在开发 Xamarin 应用,但这不会更改问题或答案的内容,因为该问题与程序的 Xamarin 部分无关。此外,Visual Studio 标记仅用于有关 Visual Studio 应用程序的问题,而不是使用它创作的代码。
1赞 ProgrammingLlama 5/31/2021
请解释“但它不起作用”是什么意思。
0赞 Salvatore Lorello 5/31/2021
update 返回此错误----- MongoError: not authorized on (User) to execute command { createUser: “newuser”, pwd: “xxx”, roles: [ { role: “readWrite”, db: “User” } ], lsid: { id: UUID(“ce6c39d4-e14c-4f6c-b5d0-d66d210e9833”) }, $clusterTime: { clusterTime: Timestamp(1622456008, 30), signature: { hash: BinData(0, F02EF0CAD605D9ECBCF3E928F84853FECE9B2829), keyId: 6968352101504122883 } }, $db: “(User)” }
0赞 prasad_ 5/31/2021
请参阅具有类似问题的 Stack Exchange 帖子:对于 mongo,无法使用错误命令 createUser 创建管理员以外的用户需要身份验证
1赞 barrypicker 6/1/2021
您连接到数据库的用户似乎无权创建其他用户。是否可以访问具有提升权限的帐户,然后重试?

答: 暂无答案