gpt4 book ai didi

mongodb - Mongo 查询失败,错误代码 13 和错误消息 'not authorized'

转载 作者:行者123 更新时间:2023-12-04 13:44:29 25 4
gpt4 key购买 nike

当我尝试对 mLab 上的 mongo 实例进行查询时发生错误。我从 Spring Boot 应用程序请求它。与数据库的连接稳定。下面是来自控制台的日志。

Monitor thread successfully connected to server with description ServerDescription{address=ds131531.mlab.com:31531, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 15]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=null, roundTripTimeNanos=138364906, setName='rs-ds131531', canonicalAddress=ds131531-a.mlab.com:31531, hosts=[ds131531-a.mlab.com:31531], passives=[], arbiters=[], primary='ds131531-a.mlab.com:31531', tagSet=TagSet{[]}, electionId=7fffffff0000000000000001, setVersion=1, lastWriteDate=Wed Jul 18 15:22:37 CEST 2018, lastUpdateTimeNanos=20828794373992}



这是确切的错误消息

Query failed with error code 13 and error message 'not authorized on pizza-store to execute command { find: "product", filter: {}, batchSize: 2147483647 }' on server ds131531.mlab.com:31531; nested exception is com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'not authorized on pizza-store to execute command { find: "product", filter: {}, batchSize: 2147483647 }' on server ds131531.mlab.com:31531



如果我从 mongo shell 进行相同的查询,则一切正常。
我已向发出请求但没有任何帮助的用户添加了 readWrite 角色和我的自定义 readProduct 角色角色。 dbOwner 和 read 是内置角色。

用户 mongo 角色:
"_id" : "pizza-db.kubiakb",
"user" : "kubiakb",
"db" : "pizza-db",
"roles" : [
{
"role" : "readProduct",
"db" : "pizza-db"
},
{
"role" : "read",
"db" : "pizza-db"
},
{
"role" : "dbOwner",
"db" : "pizza-db"
}
]

读取产品角色
{
"role" : "readProduct",
"db" : "pizza-db",
"isBuiltin" : false,
"roles" : [ ],
"inheritedRoles" : [ ],
"privileges" : [
{
"resource" : {
"db" : "pizza-db",
"collection" : "product"
},
"actions" : [
"find"
]
}
],
"inheritedPrivileges" : [
{
"resource" : {
"db" : "pizza-db",
"collection" : "product"
},
"actions" : [
"find"
]
}
]

}

编辑:
Spring application.properties
spring:
profiles: heroku
data:
mongodb:
uri: mongodb://login:pass@ds131531.mlab.com:31531/pizza-db

最佳答案

问题解决了。问题是我的 application.yml 文件中有更多配置文件,并且我没有在配置文件 heroku 中声明数据库名称,因此它从默认配置文件中读取数据库名称。
在 application.yml 文件下面

spring:
data:
mongodb:
database: pizza-store
uri: mongodb://localhost:27017

price-point-multiplier : 0.1

---
spring:
profiles: docker
data:
mongodb:
database: pizza-store
uri: mongodb://mongodb:27017

---
spring:
profiles: heroku
data:
mongodb:
uri: ${MONGODB_URI}

关于mongodb - Mongo 查询失败,错误代码 13 和错误消息 'not authorized',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51404509/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com