While testing spring-boot-docker-compose (Spring Boot 3.1) I encountered an issue regarding MongoDB autoconfiguration. My Spring Boot application got an authentication error during start up. Spring Boot was using the initDB database as authentication target.

According to the official MongoDB image documentation MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD are used to create a root user in admin database and not MONGO_INITDB_DATABASE. This would require to use admin as authentication database during autoconfiguration.

The StringBuilder in class MongoDockerComposeConnectionDetailsFactory is missing the authSource option.

[scottfrederick](https://github.com/spring-projects/spring-boot/issues/35567#issuecomment-1581048806)