Mongo服务器从Shell接受凭据,但不从Java/Scala接口接受凭据 [英] Mongo server accepts credentials from shell, but not from Java/Scala interface
问题描述
我正在开发一个Scala框架,该框架想使用Mongo Java库连接到本地MongoDB实例,但是失败了.用于连接的URI是:
I'm working on a Scala framework that wants to connect to a local MongoDB instance using the Mongo Java library, but fails. The URI it uses to connect is:
mongodb://user:pass@localhost:27017/mydb
这会导致在尝试更新集合时引发以下异常:
This causes the following exception to be raised when I try to update a collection:
com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
但是,如果我从URI中提取参数并将其提供给Mongo shell:
However, if I extract the parameters from the URI and give them to the Mongo shell:
$ mongo -u user -p pass --host localhost --port 27017 mydb
...然后它让我进入!谁能建议这可能是为什么?
...then it lets me in! Can anyone suggest why this might be?
可能但不太可能相关:在运行Windows的戴尔笔记本电脑(运行Ubuntu)的原始环境中,一切工作正常.现在,我试图在Virtualbox中运行Ubuntu的Mac笔记本电脑上运行它.一切都应该几乎相同,但显然不一样.
Possibly but unlikely to be relevant: Everything was working fine in the original environment I ran my framework in, a Dell laptop running Ubuntu. Now I'm trying to run it on a Mac laptop running Ubuntu in Virtualbox. Everything should be virtually (ha) identical, but obviously isn't somehow.
推荐答案
显然是版本不匹配.我尝试卸载Ubuntu提供的3.0.3,并使用了从mongodb.org下载的2.6.10,我的库终于可以连接了.
It was a version mismatch, apparently. I tried uninstalling the 3.0.3 that Ubuntu provided and used 2.6.10 which I downloaded from mongodb.org, and my library was finally able to connect.
这是在我在日志中发现一行时,该行从内存中类似于在用户文档中找不到凭据"之类的东西.
This was after I spotted a line in the log which from memory was something like "credentials not found in user document."
伙计,我知道在越过主要版本号时可能会出现一些破损,但是阻止较旧的客户端甚至完全无法连接似乎很极端.
Man, I know some breakage might be expected when crossing a major version number, but preventing older clients from even being able to connect at all seems pretty extreme.
这篇关于Mongo服务器从Shell接受凭据,但不从Java/Scala接口接受凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!