RMongo:使用端口转发连接到mongoDB

时间:2017-03-20 18:20:13

标签: r mongodb rmongodb rmongo

我使用端口转发连接到mongodb服务器,如下所示:

ssh -i key.pem -Nf -L 27018:xx.xxx.xxx.xxx:27017 ubuntu@xx.xxx.xxx.xxx
mongo -u user -p pass --authenticationDatabase "db" --port 27018

然后我运行R连接并查询数据库:

library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'xx.xxx.xxx.xxx', port = 27018)
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')

这在身份验证时给我一个错误:

Error in .jcall(rmongo.object@javaMongo, "Z", "dbAuthenticate", username,  : 
  com.mongodb.MongoException$Network: IOException authenticating the connection

没有端口转发,我的凭据有效:

library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'xx.xxx.xxx.xxx', port = 27017)
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')

如何在mongoDbconnect设置端口?

谢谢!

1 个答案:

答案 0 :(得分:1)

好的,这很有效。无需放置主机,因为现在我们已映射到localhost

library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'localhost', port = '27018')
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')
相关问题