在当前的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}}}
发布评论