Attempt to switch database target during SASL authentication Attempt to switch database target during SASL authentication mongodb mongodb

Attempt to switch database target during SASL authentication


spring:  data:    mongodb:      uri: mongodb://admin:admin@127.0.0.1:27017/dbname?authSource=admin

add authSource param


It seems that it's a bug in mongo DB version

4.4.3-bionic

I've changed image in docker-compose to

mongo:3

and the error went away. Uh, so many hours....


Adding spring.data.mongodb.authentication-database=admin in your application.properties will set the authentication database to admin. This is equivalent to adding ?authSource=admin in your connection string.