title: mongo db authentication error with spring (Query failed with error code 13 and error message)
body: <p>I am getting following error while trying to find records from mongodb collection.</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>my spring configuration file looks like below</p>
  
  <pre><code>     &lt;mongo:repositories
                base-package="psl.service.infra.loggerx.server" mongo-template-ref="mongoTemplate"/&gt;
  
  &lt;bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean"&gt;
      &lt;property name="host" value="${mongo.host}"/&gt;
    &lt;/bean&gt;
  
        &lt;bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"&gt;
          &lt;constructor-arg ref="mongo"/&gt;
          &lt;constructor-arg name="databaseName" value="ssprod"/&gt;
          &lt;constructor-arg name="userCredentials" ref="mongoCredentials"/&gt;
        &lt;/bean&gt;
  
        &lt;bean id="mongoCredentials" class="org.springframework.data.authentication.UserCredentials"&gt;
          &lt;constructor-arg name="username" value="${mongo.username}"/&gt;
          &lt;constructor-arg name="password" value="${mongo.password}" /&gt;
        &lt;/bean&gt;
  
  
  
      &lt;/beans&gt;
  </code></pre>
  
  <p>Credentials are correct and user has read and write access.Kindly help.</p>