dheeraj singhal
dheeraj singhal

Reputation: 53

mongo db authentication error with spring (Query failed with error code 13 and error message)

I am getting following error while trying to find records from mongodb collection.

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)

my spring configuration file looks like below

     <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>

Credentials are correct and user has read and write access.Kindly help.

Upvotes: 2

Views: 2740

Answers (1)

notionquest
notionquest

Reputation: 39226

I think the problem is that the "AuthenticationMechanism" (i.e. value is SCRAM-SHA-1) is missing in the Spring context. Please refer the below link and change the Spring context file accordingly.

Even after changing the context if you get this error, please paste the error with the latest context file.

Refer this link

Upvotes: 2

Related Questions