Manoj S Ramaswamy
Manoj S Ramaswamy

Reputation: 33

Connecting to MongoDB in scala

I was trying to connect my play-scala application to mongo db through ReactiveMongo dependencies/ libraries that I found in play framework documentation.

I have added in my conf file like this

play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
mongodb.uri = "mongodb://ege:ege123@localhost:27017/smug-studio"

but after running my application, when I am trying to access the database through postman api it throws me an exception like

{
    "Code": 0,
    "ERROR": "MongoError['Connection is missing metadata (like protocol version, etc.) The connection pool is probably being initialized.']"
}

in the logs I could find like this

[warn] r.c.a.MongoDBSystem - [Supervisor-1/Connection-2] Error while processing getNonce response #1000
[error] r.c.a.MongoDBSystem - [Supervisor-1/Connection-2] Authentication failure
reactivemongo.core.commands.FailedAuthentication: BSONCommandError['Error while processing getNonce response #1000']
    at reactivemongo.core.actors.MongoScramSha1Authentication$$anonfun$authReceive$1.$anonfun$applyOrElse$5(MongoScramSha1Authentication.scala:46)
    at reactivemongo.core.actors.MongoDBSystem.$anonfun$authenticationResponse$1(MongoDBSystem.scala:1009)
    at reactivemongo.core.actors.MongoDBSystem.updateNodeSet(MongoDBSystem.scala:971)
    at reactivemongo.core.actors.MongoDBSystem.updateNodeSet$(MongoDBSystem.scala:965)
    at reactivemongo.core.actors.StandardDBSystem.updateNodeSet(MongoDBSystem.scala:1337)
    at reactivemongo.core.actors.MongoDBSystem.authenticationResponse(MongoDBSystem.scala:1002)
    at reactivemongo.core.actors.MongoDBSystem.authenticationResponse$(MongoDBSystem.scala:998)
    at reactivemongo.core.actors.StandardDBSystem.authenticationResponse(MongoDBSystem.scala:1337)
    at reactivemongo.core.actors.MongoScramSha1Authentication$$anonfun$authReceive$1.$anonfun$applyOrElse$1(MongoScramSha1Authentication.scala:46)
    at scala.util.Either.fold(Either.scala:189)
[warn] r.c.a.MongoDBSystem - [Supervisor-1/Connection-2] Error while processing getNonce response #1001
[error] r.c.a.MongoDBSystem - [Supervisor-1/Connection-2] Authentication failure
reactivemongo.core.commands.FailedAuthentication: BSONCommandError['Error while processing getNonce response #1001']
    at reactivemongo.core.actors.MongoScramSha1Authentication$$anonfun$authReceive$1.$anonfun$applyOrElse$5(MongoScramSha1Authentication.scala:46)
    at reactivemongo.core.actors.MongoDBSystem.$anonfun$authenticationResponse$1(MongoDBSystem.scala:1009)
    at reactivemongo.core.actors.MongoDBSystem.updateNodeSet(MongoDBSystem.scala:971)
    at reactivemongo.core.actors.MongoDBSystem.updateNodeSet$(MongoDBSystem.scala:965)
    at reactivemongo.core.actors.StandardDBSystem.updateNodeSet(MongoDBSystem.scala:1337)
    at reactivemongo.core.actors.MongoDBSystem.authenticationResponse(MongoDBSystem.scala:1002)
    at reactivemongo.core.actors.MongoDBSystem.authenticationResponse$(MongoDBSystem.scala:998)
    at reactivemongo.core.actors.StandardDBSystem.authenticationResponse(MongoDBSystem.scala:1337)
    at reactivemongo.core.actors.MongoScramSha1Authentication$$anonfun$authReceive$1.$anonfun$applyOrElse$1(MongoScramSha1Authentication.scala:46)
    at scala.util.Either.fold(Either.scala:189)

What should I required to do to fix the issue?

Upvotes: 0

Views: 1106

Answers (1)

Ahmad Ragab
Ahmad Ragab

Reputation: 1117

If you can connect to mongo on the shell, then the issue might be that you have not set the authMode or authMechanism correctly on the url:

mongodb://ege:ege123@localhost:27017/smug-studio?authMechanism=SCRAM-SHA-1

or

mongodb://ege:ege123@localhost:27017/smug-studio?authMode=SCRAM-SHA-1

http://mongodb.github.io/mongo-java-driver/3.0/driver/reference/connecting/authenticating/

Upvotes: 1

Related Questions