gpt4 book ai didi

java - spring 的 mongo db 身份验证错误(查询失败,错误代码 13 和错误消息)

转载 作者:行者123 更新时间:2023-11-30 07:14:02 24 4
gpt4 key购买 nike

我在尝试从 mongodb 集合中查找记录时遇到以下错误。

org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 13 and error message 'not authorized for query on ssprod.logger_user_activities' on server beta.redbus.co:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'not authorized for query on ssprod.logger_user_activities' on server beta.redbus.co:27017
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:96)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2011)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1894)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1705)
at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1688)
at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:601)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:268)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:193)
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findAll(SimpleMongoRepository.java:47)

我的 spring 配置文件如下所示

     <mongo:repositories
base-package="psl.service.infra.loggerx.server" mongo-template-ref="mongoTemplate"/>

<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<property name="host" value="${mongo.host}"/>
</bean>

<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongo"/>
<constructor-arg name="databaseName" value="ssprod"/>
<constructor-arg name="userCredentials" ref="mongoCredentials"/>
</bean>

<bean id="mongoCredentials" class="org.springframework.data.authentication.UserCredentials">
<constructor-arg name="username" value="${mongo.username}"/>
<constructor-arg name="password" value="${mongo.password}" />
</bean>



</beans>

凭据正确,用户具有读写访问权限。请提供帮助。

最佳答案

我认为问题在于 Spring 上下文中缺少“AuthenticationMechanism”(即值为 SCRAM-SHA-1)。请引用下面的链接并相应地更改 Spring 上下文文件。

即使在更改上下文后,如果出现此错误,也请将错误粘贴到最新的上下文文件中。

Refer this link

关于java - spring 的 mongo db 身份验证错误(查询失败,错误代码 13 和错误消息),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38726863/

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