首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在scala中连接到MongoDB

在scala中连接到MongoDB
EN

Stack Overflow用户
提问于 2018-07-10 08:55:13
回答 1查看 905关注 0票数 0

我试图通过我在play框架文档中找到的ReactiveMongo依赖项/库将我的play-scala应用程序连接到mongo db。

我在conf文件中添加了如下内容

代码语言:javascript
复制
play.modules.enabled += "play.modules.reactivemongo.ReactiveMongoModule"
mongodb.uri = "mongodb://ege:ege123@localhost:27017/smug-studio"

但是在运行我的应用程序之后,当我试图通过postman api访问数据库时,它抛出了一个异常,比如

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

在日志里我可以找到这样的东西

代码语言:javascript
复制
[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)

我需要做些什么来解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2018-07-10 22:26:55

如果你可以在shell上连接到mongo,那么问题可能是你没有在url上正确设置authModeauthMechanism

代码语言:javascript
复制
mongodb://ege:ege123@localhost:27017/smug-studio?authMechanism=SCRAM-SHA-1

代码语言:javascript
复制
mongodb://ege:ege123@localhost:27017/smug-studio?authMode=SCRAM-SHA-1

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51255856

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档