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