mongodb—创建用户时,我应该使用哪个身份验证数据库

发布于 2025-01-20 10:14:40 字数 774 浏览 4 评论 0 原文

在当前的mongo实例中,

遵循mongo最佳实践:在系统数据库(admin)中创建用户,而不是各自的数据库,并将admin数据库作为授权数据库,

但在系统数据库(admin)中创建用户时在独立函数中进行测试时,在代码中进行测试时正常工作, 之前,请获得异常

(Docker)在创建用户使用命令

开关到Admin

Connection字符串的使用

mongodb:// :@xxxxxxx:27017/admin

引起的:com.mongodb.mongocommandexception:命令失败 错误263(操作notsupportedIntransaction):'无法运行命令 针对交易中的“管理员”数据库。在服务器xxxxxxxxxxx上。 完整响应是{“ aperightime”:{“ $ timestamp”:{“ t”: 1649307185,“ i”:1}},“ ok”:0.0,“ errmsg”:“不能反对命令 交易中的“管理员”数据库。”,“代码”:263,“代码ename”: “操作notsupportedIntransaction”,“ $ clustertime”:{“ clustertime”: {“ $ timestamp”:{“ t”:1649307185,“ i”:1}},“ signature”:{“ hash”: {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": “ 00”}},“ keyId”:0}}}

In Current Mongo Instance

Following the Mongo Best Practices : Users are created in system database(Admin) rather than respective database and made admin database as authorization database

But creating users in system database (admin) works fine when tested in standalone functions when checked with code(Docker) getting exceptions

Also before creating user used the command

switch to admin

connection string used:

mongodb:// :@xxxxxxx:27017/admin

Caused by: com.mongodb.MongoCommandException: Command failed with
error 263 (OperationNotSupportedInTransaction): 'Cannot run command
against the 'admin' database in a transaction.' on server xxxxxxxxxxx.
The full response is {"operationTime": {"$timestamp": {"t":
1649307185, "i": 1}}, "ok": 0.0, "errmsg": "Cannot run command against
the 'admin' database in a transaction.", "code": 263, "codeName":
"OperationNotSupportedInTransaction", "$clusterTime": {"clusterTime":
{"$timestamp": {"t": 1649307185, "i": 1}}, "signature": {"hash":
{"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType":
"00"}}, "keyId": 0}}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文