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

时间:2016-08-02 17:23:46

标签: java spring mongodb

我在尝试从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>

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

1 个答案:

答案 0 :(得分:1)

我认为问题在于&#34; AuthenticationMechanism&#34; Spring上下文中缺少(即值为SCRAM-SHA-1)。请参阅以下链接并相应地更改Spring上下文文件。

如果出现此错误,即使更改了上下文,也请使用最新的上下文文件粘贴错误。

Refer this link