Exception authenticating MongoCredential and Uncategorized Mongo Db Exception

Put these configuration in your application properties file:

spring.data.mongodb.host= YOUR_HOST like 192.168.x.x
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=admin
spring.data.mongodb.password=PASSWORD
spring.data.mongodb.database=DB_NAME

As per #46934427, setting spring.data.mongodb.authentication-database=admin would probably fix your issue.

The default database in MongoDB is test, therefore, it's likely you are attempting to authenticate against the test database. Switching to the admin database (the common place for users to be created), might fix your issue.


You could try this:

spring.data.mongodb.uri=mongodb://user:passwod@localhost/test?authSource=admin