2

I'm working on a Scala framework that wants to connect to a local MongoDB instance using the Mongo Java library, but fails. The URI it uses to connect is:

mongodb://user:pass@localhost:27017/mydb

This causes the following exception to be raised when I try to update a collection:

com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}

However, if I extract the parameters from the URI and give them to the Mongo shell:

$ mongo -u user -p pass --host localhost --port 27017 mydb

...then it lets me in! Can anyone suggest why this might be?

Possibly but unlikely to be relevant: Everything was working fine in the original environment I ran my framework in, a Dell laptop running Ubuntu. Now I'm trying to run it on a Mac laptop running Ubuntu in Virtualbox. Everything should be virtually (ha) identical, but obviously isn't somehow.

Sean
  • 29,130
  • 4
  • 80
  • 105
  • I'd check if your server accept remote connections, also if your shell uses a different jdk than your java application or if your firewall (iptables perhaps) are bothering – Federico Piazza Jun 12 '15 at 01:19
  • Have you read this: http://stackoverflow.com/questions/18216712/cannot-authenticate-into-mongo-auth-fails ? – user3707125 Jun 12 '15 at 01:31
  • @user3707125 That question seems to deal with authenticating as an admin on an existing connection versus making a new connection. In my case I'm getting conflicting responses with two different ways of making a new connection (shell vs. API). – Sean Jun 12 '15 at 16:37

2 Answers2

0

It was a version mismatch, apparently. I tried uninstalling the 3.0.3 that Ubuntu provided and used 2.6.10 which I downloaded from mongodb.org, and my library was finally able to connect.

This was after I spotted a line in the log which from memory was something like "credentials not found in user document."

Man, I know some breakage might be expected when crossing a major version number, but preventing older clients from even being able to connect at all seems pretty extreme.

Sean
  • 29,130
  • 4
  • 80
  • 105
0

In my case i had to upgrade my mongo driver from v2.12.5 to v2.13.0 to get it work.

codereal
  • 150
  • 1
  • 11