[英]Connecting to MongoDB replica set with rmongodb
Has anyone been able to connect to a MongoDB replica set using rmongodb
? 有没有人能够使用
rmongodb
连接到MongoDB副本集? No matter how I configure mongo.create
I get an authentication error, even though the same host/username/password work fine when connecting via the mongo
shell. 无论我如何配置
mongo.create
,即使通过mongo
shell进行连接时,相同的主机/用户名/密码都可以正常工作,但mongo.create
收到身份验证错误。
My code does the equivalent of: 我的代码等效于:
> mongo.create(c("rs-1.mysite.com:12345","rs-2.mysite.com:12345"), "rsName", "user", "password", "my_db")
Unable to connect to replset
Authentication failed.
Update: 更新:
Looking at the logs of all the nodes in the replica set, I do not see any attempt to authenticate when I run the code above. 查看副本集中所有节点的日志,当我运行上面的代码时,我看不到任何尝试进行身份验证的尝试。 Therefore, this may be a
rmongodb
bug. 因此,这可能是
rmongodb
错误。
As Sim has noted, rmongodb 1.0.3 does not resolve hostnames . 正如Sim所指出的那样, rmongodb 1.0.3不能解析主机名 。
It is, however, possible to connect to replica sets from rmongodb with with a few caveats: 但是,可以从rmongodb连接到副本集,但要注意以下几点:
So my working connect string looks like: 所以我的工作连接字符串看起来像:
mongo.create(c("192.168.1.123:27017","192.168.1.124:27018","192.168.1.125:27017"),"","user","password", "thedb")
NB: I only tested this with MongoDB 2.2.0. 注意:我仅使用MongoDB 2.2.0进行了测试。
Looking at the C source, it seems that rmongodb
does not resolve hostnames into IP addresses. 从C源代码来看,
rmongodb
似乎没有将主机名解析为IP地址。 The only way this works is if you pass an IP address string to the driver... 唯一可行的方法是将IP地址字符串传递给驱动程序。
By passing an IP address and port number you can connect to one of the nodes. 通过传递IP地址和端口号,您可以连接到其中一个节点。 I still cannot get
rmongodb
to successfully connect to a replica set. 我仍然无法使
rmongodb
成功连接到副本集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.