我使用play-reactivemongo连接到MongoDB 3时遇到问题,遇到"'not authorized for query on XXX‘(code =13)’“问题。当MongoDB在没有--auth的情况下启动时,程序运行完全正常。
数据库版本应为3.0.4,如日志所示。
2015-10-24T15:58:09.868+0800 I CONTROL [initandlisten] db version v3.0.4我使用的是0.11.7play2-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应该是默认的,对吗?
发布于 2016-11-24 21:28:12
将以下内容附加到连接字符串后对我有效
authMode=scram-sha1因此,最终的连接字符串是
mongodb://user:pass@ipaddress:27017/litmus?3treadPreference=primary&authMode=scram-sha1我也有nodejs脚本连接到相同的数据库,有趣的是,它连接得很好,没有附加authMode=scram-sha1标志。
在反应式mongo中似乎是未处理的情况
发布于 2015-10-25 01:52:58
对不起,我在mongodb.uri中打错了字
authMode=?authMode=scram-sha1并使DB向mongodb-cr认证。但是,在第一次访问数据库时,我仍然收到"not authorized to query“错误,随后的数据库访问也没有问题。在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我最好明天开始另一个问题。
https://stackoverflow.com/questions/33318884
复制相似问题