Spring boot connection mongodb reported an error.

  mongodb, question

Just started to learn mongodb and wrote a simple spring boot program to connect mongo.
, you can connect to mongo correctly using the following configuration:

spring.data.mongodb.host=10.159.14.19
 spring.data.mongodb.port=9001
 spring.data.mongodb.authentication-database=admin
 spring.data.mongodb.database=esign
 spring.data.mongodb.username=esign_write
 spring.data.mongodb.password=NTc2OTQ1YjcwN2Z

However, an error will be reported using the following configuration:

spring.data.mongodb.uri=mongodb://esign_write:NTc2OTQ1YjcwN2Z@10.159.14.19:9001/esign
 spring.data.mongodb.authentication-database=admin

The error message is as follows:

com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='esign_write', source='esign', password=<hidden>, mechanismProperties={}}
 at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:61) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.DefaultAuthenticator.authenticate(DefaultAuthenticator.java:32) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.InternalStreamConnectionInitializer.authenticateAll(InternalStreamConnectionInitializer.java:99) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:44) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128) ~[mongodb-driver-core-3.2.2.jar:na]
 at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
 Caused by: com.mongodb.MongoCommandException: Command failed with error 18: 'Authentication failed.' on server 10.159.14.19:9001. The full response is   { "ok" : 0.0, "errmsg" : "Authentication failed.", "code" : 18, "codeName" : "AuthenticationFailed" }
 at com.mongodb.connection.CommandHelper.createCommandFailureException(CommandHelper.java:170) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.CommandHelper.receiveCommandResult(CommandHelper.java:123) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:32) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.SaslAuthenticator.sendSaslStart(SaslAuthenticator.java:95) ~[mongodb-driver-core-3.2.2.jar:na]
 at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:45) ~[mongodb-driver-core-3.2.2.jar:na]
 ... 6 common frames omitted

What is the reason for this?

spring.data.mongodb.uri=mongodb://esign_write:NTc2OTQ1YjcwN2Z@10.159.14.19:9001/esign
spring.data.mongodb.authentication-database=admin
Change to
spring.data.mongodb.uri=mongodb://esign_write:NTc2OTQ1YjcwN2Z@10.159.14.19:9001/
spring.data.mongodb.database=esign
spring.data.mongodb.authentication-database=admin

I don’t know why I can try it