简体   繁体   中英

Connecting to mongodb on a remote server from R

I have been trying to find answers to connect to the MongoDB which sits on the server(Linux) from my local windows machine. I have stumbled upon answers like use packages such as RMongo and Mongolite. But they seem to work when I want to connect to MongoDB that is on my local machine on localhost. I know how to do it in python by using SSHTunnel to connect to the server and then use pymongo to play with MongoDB. I am looking for python equivalent workaround for R. The python code is as follows:

mongo_host = ''
mongo_user = ''
mongo_pass = ''    

server = SSHTunnelForwarder(
        mongo_host,
        ssh_username = mongo_user,
        ssh_password=mongo_pass,
        remote_bind_address=('127.0.0.1', 27017)
        ) 
server.start()   
client = pymongo.MongoClient('127.0.0.1',server.local_bind_port)
db = client.myDB

Thanks a lot in advance for your help.

Using the mongolite package you should be able to access your db via its' URL:

mongo(collection = "test", db = "test", url = "mongodb://localhost",
verbose = FALSE, options = ssl_options())

See ?mongolite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM