我使用端口转发连接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中设置我的端口
谢谢!
发布于 2017-03-21 02:35:17
好了,这行得通。无需放置主机,因为现在我们已映射到localhost
library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'localhost', port = '27018')
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')https://stackoverflow.com/questions/42911155
复制相似问题