我正在尝试通过 Spring Boot 应用程序将数据插入启用身份验证的 MongoDB 3.4 GridFS 存储,但我不断收到此错误:
Query failed with error code 13 and error message 'not authorized on user to execute command { find: \"fs.files\", filter: { metadata.fieldname: \"someContent\" } }' on server ip:27017"
我为此创建了一个具有“ super 用户”权限的用户:
use admin
db.createUser(
{
user: "admin",
pwd: "password",
roles:["root"]
})
我的 spring boot application.properties 是:
spring.data.mongodb.host=ip
spring.data.mongodb.port=27017
spring.data.mongodb.username=admin
spring.data.mongodb.password=password
spring.data.mongodb.database=user
spring.data.mongodb.authentication-database=admin
我已经尝试过“旧的”MongoDB 角色,但没有成功:
db.createUser(
{
user: "admin",
pwd: "password",
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
{ role: "clusterAdmin", db: "admin" }
]
})
读取和写入其他(非 gridFS)数据库完美无缺。 关于如何解决这个问题的任何想法?
最佳答案
解决方法: 我还有一个 AbstractMongoConfiguration 类。
@Configuration
public class SpringMongoConfig extends AbstractMongoConfiguration {
//some code...
}
删除它解决了它。 您必须使用 application.properties 或 java 类进行 MongoDB 配置。
关于spring - MongoDB GridFS 身份验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45591005/