1

I have an issue connecting to my mongo database with Casbah and it works fine with ReactiveMongo. Here is the code used with Casbah: val client = MongoClient(MongoClientURI("my_uri")) and with ReactiveMongo: this.driver(actorSystem).connection(MongoConnection.parseURI("my_uri")). the error I get with with Casbah is: { "serverUsed" : "host:27017" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}. Any idea where this could come from ?

mravey
  • 4,380
  • 2
  • 21
  • 31
  • You're getting an "auth failed" message - how are you setting your mongodb credentials? – Ross May 22 '15 at 09:01
  • In both ways they're set in the mongo uri like this: `mongodb://login:password@host:port/database` – mravey May 22 '15 at 10:24
  • What version of MongoDB and what version of Casbah? – Ross May 22 '15 at 10:30
  • Mongodb version 2.6.8 and Casbah version 2.8.1 – mravey May 22 '15 at 14:07
  • What does `db.getUser()` output? http://docs.mongodb.org/manual/reference/method/db.getUser/ – Ross May 26 '15 at 09:37
  • Thanks Ross, I've found the issue the user does not exist in the database. If I try to login without login/password it works. But I don't understand why ReactiveMongo can login but Casbah can't. – mravey May 26 '15 at 13:23

1 Answers1

0

You may need to explicitly set the authMechanism property if not using the default for the MongoDB Server.

Before MongoDB 3.0 the default authentication mechanism was MONGODB-CR, the "MongoDB Challenge-Response" protocol. In MongoDB 3.0 the default was changed to SCRAM-SHA-1.

If no authMechanism is set then the underlying Java driver will pick the most secure mechanism available based on the sever version.

Try updating your Connection String to:

mongodb://login:password@host:port/database?authMechanism=MONGODB-CR
Ross
  • 17,861
  • 2
  • 55
  • 73