我使用这样的端口转发连接到 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
?
谢谢!