Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Not A Bug
-
None
-
None
-
None
-
Unknown
Description
I am using the mongodb url
mongodb://?collection=sales&database=sales&hosts=172.17.0.7%3A27017&operation=findAll&password=xxxxxx&username=myuser
When using the hosts parameter to authenticate to a mongodb server, it fails with
Caused by: com.mongodb.MongoCommandException: Command failed with error 18 (AuthenticationFailed): 'Authentication failed.' on server 172.17.0.7:27017. The full response is {"ok": 0.0, "errmsg": "Authentication failed.", "code": 18, "codeName": "AuthenticationFailed"}
mongo server shows
"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"myuser","authenticationDatabase":"admin","remote":"172.17.0.6:60642","extraInfo":{},"error":"UserNotFound: Could not find user \"myuser\" for db \"admin\""
MongoDB connection string uses admin database when no authentication database is specified
https://github.com/mongodb/mongo-java-driver/blob/r4.1.0/driver-core/src/main/com/mongodb/ConnectionString.java#L63
https://github.com/mongodb/mongo-java-driver/blob/r4.1.0/driver-core/src/main/com/mongodb/ConnectionString.java#L729
I think the database should be used in camel-mongodb authentication mechanism, at least I changed the code and it worked.
mongoClient = MongoClients.create(String.format("mongodb://%s%s", credentials, hosts));