Query failed with error code 13 and error message

0

I have a problem with a Spring boot project 2.0.3.RELEASE + mongodb 4

- Instance my DB as

mongod --auth --config mongod.conf --dbpath=\data\mongo4\

- Create the user in the following two ways

db.createUser(
  {
    user: "us1",
    pwd: "abc123",
    roles: [ { role: "readWrite", db: "dbTest" }]
  }
)

db.createUser(
  {
    user: "us2",
    pwd: "abc123",
    roles: [ 
        { role: "userAdminAnyDatabase", db: "admin" },
        { role: "root", db: "admin" },
        { role: "readWrite", db: "dbTest" }
    ]
  }
)

- In my application.properties file it was configured like this

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=dbTest
spring.data.mongodb.username=user
spring.data.mongodb.password=pass
spring.data.mongodb.authentication-database=dbTest

However, the error that shows me in Spring is the following:

org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 13 and error message 'command find requires authentication' on server localhost:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 13 and error message 'command find requires authentication' on server localhost:27017

I searched for the error but I can not fix it

    
asked by CarlG 24.10.2018 в 14:43
source

1 answer

0

It gives you authentication error because you are not providing the user data and password that correspond to those of your created users.

spring.data.mongodb.username=user
spring.data.mongodb.password=pass

These settings do not have the value us1 or us2 that are the users that you created, nor the password abc123 .

    
answered by 16.11.2018 в 22:34