Environment
spring-boot 1.3.2
spring-mongo 0.8.0
build my spring-boot microservice with gradle.
Problem
one of mongo database enable the auth,so i configure these arguments in application.yml
spring:
data:
mongo:
username:xxx
password:xxx
authentication-database:xxx
it works well for mongodb which has set the auth.
but I got error with mongdb which has not set the auth even I set the username="",password="".it fail with auth.
Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "code" : 18 , "errmsg" : "Authentication failed."} at com.mongodb.CommandResult.getException(CommandResult.java:76) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.CommandResult.throwOnError(CommandResult.java:140) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBPort$SaslAuthenticator.authenticate(DBPort.java:903) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBPort.authenticate(DBPort.java:436) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBPort.checkAuth(DBPort.java:447) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBTCPConnector.doOperation(DBTCPConnector.java:207) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBCollectionImpl.createIndex(DBCollectionImpl.java:392) ~[mongo-java-driver-2.13.3.jar:na] at com.mongodb.DBCollection.createIndex(DBCollection.java:597) ~[mongo-java-driver-2.13.3.jar:na]
My question is how to remove the mongo.username,password key dynamic for these mongo db which has not set auth?
also I am curious about why cannot remove the key in application.yml file.while have seen that we can automatic property expansion using Maven or gradle in this document:property expansion
Update if just leave these key empty,still get error
The full response is { "ok" : 0.0, "errmsg" : "Invalid database name: ''", "code" : 73 }}}]