I connect to a mongodb server using port forwarding like this:
ssh -i key.pem -Nf -L 27018:xx.xxx.xxx.xxx:27017 [email protected]
mongo -u user -p pass --authenticationDatabase "db" --port 27018
Then I run R to connect and query the database:
library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'xx.xxx.xxx.xxx', port = 27018)
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')
This gives me an error while authentication:
Error in .jcall(rmongo.object@javaMongo, "Z", "dbAuthenticate", username, :
com.mongodb.MongoException$Network: IOException authenticating the connection
Without port forwarding, my credentials work:
library(RMongo)
mg1 <- mongoDbConnect(dbName = 'db', host = 'xx.xxx.xxx.xxx', port = 27017)
auth <- dbAuthenticate(rmongo.object = mg1, username = 'user', password = 'pass')
How do I set my port in mongoDbconnect?
Thanks!
Ok, this works. No need to put the host because now we are mapped to the
localhost: