0

我在使用 play-reactivemongo 连接到 MongoDB 3 时遇到问题,并且遇到了“'未授权查询 XXX'(代码 = 13)”问题。当 MongoDB 在没有 --auth 的情况下启动时,该程序运行得非常好。

数据库版本应为 3.0.4,如日志所示。

2015-10-24T15:58:09.868+0800 I CONTROL  [initandlisten] db version v3.0.4

我使用了 0.11.7 版 play2-reactivemongo 插件。

libraryDependencies ++= Seq(
  "org.reactivemongo" %% "play2-reactivemongo" % "0.11.7.play24",

我已经像这样在 mongodb.uri 中指定了 authMode。

mongodb.uri = "mongodb://postsUser:12345678@localhost:27017/posts?authMode=?authMode=scram-sha1&authSource=posts&rm.tcpNoDelay=true"

我在 mongodb.log 中发现了以下错误。

2015-10-24T16:41:24.977+0800 I ACCESS   [conn105] Failed to authenticate postsUser@posts with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

为什么使用 MONGODB-CR 而不是 SCRAM-SHA-1?假设 SCRAM-SHA-1 应该是默认值,对吧?

4

2 回答 2

1

将以下内容附加到连接字符串对我有用

authMode=scram-sha1

所以最终的连接字符串是

mongodb://user:pass@ipaddress:27017/litmus?3treadPreference=primary&authMode=scram-sha1

我也有 nodejs 脚本连接到同一个数据库,有趣的是它连接完美而没有附加authMode=scram-sha1标志。

在反应式 mongo 中似乎是未处理的案例

于 2016-11-24T13:28:11.647 回答
0

抱歉,我在 mongodb.uri 中打错字了

authMode=?authMode=scram-sha1

并导致数据库使用 mongodb-cr 进行身份验证。但是,我在第一次访问数据库时仍然收到“未授权查询”错误,随后的数据库访问正常。在 mongodb.log 中,我可以看到以下内容。

2015-10-25T01:28:45.242+0800 I QUERY    [conn33] assertion 13 not authorized for query on posts.posts ns:posts.posts query:{}
2015-10-25T01:28:45.247+0800 I ACCESS   [conn33] Successfully authenticated as principal postsUser on posts

我最好明天开始另一个问题。

于 2015-10-24T17:52:57.957 回答