Mongo server accepts credentials from shell but not from Java / Scala interface

I am working on a Scala framework that wants to connect to a local instance of MongoDB using the Mongo Java library, but does not work. The URI that it uses to connect is:

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

When you try to update a collection, the following exception occurs:

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

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

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

... then he lets me! Can anyone guess why this might be?

Perhaps, but it is unlikely to matter: everything works fine in the original environment in which I ran my infrastructure, a Dell laptop running Ubuntu. Now I'm trying to run it on a Mac laptop running Ubuntu in Virtualbox. Everything should be practically (ha) the same, but obviously this is not so.

+2
source share
2 answers

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

This was after I saw a line in the log that looked like "credentials not found in user document" from memory.

Man, I know that when switching to the main version number, some kind of breakdown may occur, but not allowing older clients to even connect at all, it seems pretty extreme.

0
source

In my case, I had to update the mongo driver from v2.12.5 to v2.13.0 to make it work.

0
source

All Articles