env: -Spring Boot 2.1.0(具有默认的spring依赖项)。
properties config: 数据: mongodb: uri:mongodb:// $ USER:$ PWD @ HOST:27017,HOST:27018 / $ DATABASE
我的pojo对象之一使用Index(unique = true),我使用mongo存储库进行CRUD操作。
因此,当启动弹簧启动时,我有了这个堆栈:
com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'not authorized on DATABASE to execute command { createIndexes: "XXX
a", indexes: [ { key: { oid: 1 }, name: "oid", ns: "XXXX", unique: true } ] }' on server XXXX:27017. The full response is { "ok" : 0.0, "errmsg"
: "not authorized on XXX to execute command { createIndexes: \"XXXX\", indexes: [ { key: { oid: 1 }, name: \"oid\", ns: \"XXXXX\", unique:
true } ] }", "code" : 13, "codeName" : "Unauthorized" }
从mongo.log登录:
2018-11-16T10:19:44.897+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46678 #169 (5 connections now open)
2018-11-16T10:19:44.938+0100 I NETWORK [conn169] received client metadata from 127.0.0.1:46678 conn169: { driver: { name: "mongo-java-driver", version: "3.8.2" }, os
: { type: "Linux", name: "Linux", architecture: "amd64", version: "2.6.32-642.15.1.el6.x86_64" }, platform: "Java/Oracle Corporation/1.8.0_77-b03" }
2018-11-16T10:19:46.062+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46680 #170 (6 connections now open)
2018-11-16T10:19:46.062+0100 I NETWORK [conn170] received client metadata from 127.0.0.1:46680 conn170: { driver: { name: "mongo-java-driver", version: "3.8.2" }, os
: { type: "Linux", name: "Linux", architecture: "amd64", version: "2.6.32-642.15.1.el6.x86_64" }, platform: "Java/Oracle Corporation/1.8.0_77-b03" }
2018-11-16T10:19:46.077+0100 I ACCESS [conn170] Unauthorized: not authorized on xxx to execute command { createIndexes: "xxxx", indexes: [ { key: { oid:
1 }, name: "oid", ns: "xxxxx", unique: true } ] }
2018-11-16T10:19:46.200+0100 I - [conn170] end connection 127.0.0.1:46680 (6 connections now open)
2018-11-16T10:19:46.200+0100 I - [conn169] end connection 127.0.0.1:46678 (5 connections now open)
当我直接使用mongo shell时:
mongo mongodb://$USER:$PWD@HOST:27017,HOST:27018/$DATABASE
我可以正确执行createIndexes。
从mongo.log登录:
2018-11-16T10:21:16.448+0100 I NETWORK [thread1] connection accepted from 127.0.0.1:46682 #171 (5 connections now open)
2018-11-16T10:21:16.448+0100 I NETWORK [conn171] received client metadata from 127.0.0.1:46682 conn171: { driver: { name: "MongoDB Internal Client", version: "3.4.9"
}, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: "Kernel 2.6.32-642.15.1.el6.x86_64" } }
2018-11-16T10:21:16.485+0100 I ACCESS [conn171] Successfully authenticated as principal XX on XX
2018-11-16T10:21:16.486+0100 I NETWORK [thread1] connection accepted from XXX:59698 #172 (6 connections now open)
2018-11-16T10:21:16.486+0100 I NETWORK [conn172] received client metadata from XX:59698 conn172: { driver: { name: "MongoDB Internal Client", version: "3.4
.9" }, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: "Kernel 2.6.32-642.15.1.el6.x86_64" } }
2018-11-16T10:21:16.522+0100 I ACCESS [conn172] Successfully authenticated as principal XX on XX
2018-11-16T10:21:16.523+0100 I NETWORK [thread1] connection accepted from XXX:59702 #173 (7 connections now open)
2018-11-16T10:21:16.524+0100 I NETWORK [conn173] received client metadata from XX:59702 conn173: { application: { name: "MongoDB Shell" }, driver: { name:
"MongoDB Internal Client", version: "3.4.9" }, os: { type: "Linux", name: "Red Hat Enterprise Linux Server release 6.8 (Santiago)", architecture: "x86_64", version: "
Kernel 2.6.32-642.15.1.el6.x86_64" } }
**2018-11-16T10:21:16.528+0100 I ACCESS [conn173] Successfully authenticated as principal XX on XX
2018-11-16T10:21:16.533+0100 I ACCESS [conn173] Successfully authenticated as principal XX on XX**
2018-11-16T10:21:16.538+0100 I ACCESS [conn173] Unauthorized: not authorized on admin to execute command { getLog: "startupWarnings" }
2018-11-16T10:21:16.541+0100 I ACCESS [conn173] Unauthorized: not authorized on admin to execute command { replSetGetStatus: 1.0, forShell: 1.0 }
2018-11-16T10:21:22.190+0100 I -[conn173] end connection XXX:59702 (7 connections now open)
2018-11-16T10:21:22.195+0100 I -[conn171] end connection 127.0.0.1:46682 (6 connections now open)
2018-11-16T10:21:22.195+0100 I -[conn172] end connection XXX:59698 (6 connections now open)
使用mongoshell,在执行createIndexes之前,我已“成功通过身份验证为主体”。
那为什么弹簧靴会是这种情况?
没有副本集,我没有错误。