Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SC
问题1:Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='root', source='test01', password=<hidden>, mechanismProperties=<hi
问题1:
Caused by: com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='root', source='test01', password=<hidden>, mechanismProperties=<hidden>}
原因:mongodb中没有创建用户及分配内置角色,
解决方法如下:
鼠标右键:点击Add User... 弹出下图
设置用户名和密码,以及勾选相应的权限
权限详解参考:https://www.cnblogs.com/sz-wenbin/p/11010403.html
Save之后,相应的yml配置文件账户密码要对应下图:
然后进行测试:这里就一笔带过,如下图:
成功添加到数据库。
问题二:
Caused by: com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'not authorized on test01 to execute command { update: "logs", ordered: true, updates: [ { q: { _id: 5 }, u: { _id: 5, name: "zhangsan", age: 18, _class: "com.example.mongodb.entity.User" }, upsert: true } ] }' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "not authorized on test01 to execute command { update: \"logs\", ordered: true, updates: [ { q: { _id: 5 }, u: { _id: 5, name: \"zhangsan\", age: 18, _class: \"com.example.mongodb.entity.User\" }, upsert: true } ] }", "code": 13, "codeName": "Unauthorized"}
原因:yml配置文件没有添加用户和密码------>(前提:已经创建了用户及设置了权限)
解决方法如下:
测试成功添加
有不足之处,欢迎各位大神评论区补充!!!
更多推荐
所有评论(0)