i'm trying to create a simple java application with mongodb i'm trying to do it with docker but it's not working i`m create a yaml file docker-compose :
version: "3.8"
services:
mongodb:
image: mongo
container_name: mongodb
ports:
- 27017:27017
volumes:
- data:/data
environment:
- MONGO_INITDB_ROOT_USERNAME=rootuser
- MONGO_INITDB_ROOT_PASSWORD=rootpass
mongo-express:
image: mongo-express
container_name: mongo-express
restart: always
ports:
- 8081:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
- ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass
- ME_CONFIG_MONGODB_SERVER=mongodb
volumes:
data: {}
networks:
default:
name: mongodb_network
and in the properties file :
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=rootuser
spring.data.mongodb.password=rootpass
spring.data.mongodb.database=demo
spring.data.mongodb.port=27017
spring.data.mongodb.host=localhost
but when i try to use some api this exeption is Thrown away :
2022-01-30 19:22:15.309 ERROR 27632 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].
[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with
path [] threw exception [Request processing failed; nested exception is
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating
MongoCredential{mechanism=SCRAM-SHA-1, userName='rootuser', source='admin', password=
<hidden>, mechanismProperties=<hidden>}; nested exception is
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-
SHA-1, userName='rootuser', source='admin', password=<hidden>, mechanismProperties=<hidden>}]
with root cause
com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed):
'Authentication failed.' on server localhost:27017. The full response is {"ok": 0.0,
"errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
please can someone help me understand why it's happening