cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Sud Regular Visitor
Regular Visitor

Mongodb connection using r scripts

Hello All,

I'm trying to connect to mongodb having SSH credentials but facing problem to connect using mongolite package.

But at the same time to my local mongodb using credentials I'm able to connect. Any help on this?

Regards,
Sud
1 ACCEPTED SOLUTION

Accepted Solutions
v-fengyz-msft Frequent Visitor
Frequent Visitor

Re: Mongodb connection using r scripts

@Sud

 

What’s the error message you got?

 

By default, MongoDB is not allowed to remote access, you need to enable remote access by modifying mongod.conf file.  

 

See:  MongoDB – Allow remote access

 

Then to connect to MongoDB via an SSH tunnel, we need to setup the tunnel separately with an SSH client.  

 

For example the mongolite manual contains this example:

 

con <- mongo("mtcars", url = "mongodb://readwrite:test@ds043942.mongolab.com:43942/jeroen_test")

  

Assume we want to tunnel through dev.opencpu.org which runs an SSH server on the standard port 22 with username jeroen. To initiate a tunnel from localhost:9999 to ds043942.mongolab.com:43942 via the ssh server dev.opencpu.org:22, open a terminal and run:

 

ssh -L 9999:ds043942.mongolab.com:43942 jeroen@dev.opencpu.org -vN -p22

  

At last, we can connect to our ssh client which tunnel traffic to MongoDB server. In this example we run the ssh client on localhost port 9999:

 

con <- mongo("mtcars", url = "mongodb://readwrite:test@localhost:9999/jeroen_test")

 

con$insert(mtcars)

 

For more information, please check : SSH Tunnel

 

Regards,

Pirlo Zhang

View solution in original post

1 REPLY 1
v-fengyz-msft Frequent Visitor
Frequent Visitor

Re: Mongodb connection using r scripts

@Sud

 

What’s the error message you got?

 

By default, MongoDB is not allowed to remote access, you need to enable remote access by modifying mongod.conf file.  

 

See:  MongoDB – Allow remote access

 

Then to connect to MongoDB via an SSH tunnel, we need to setup the tunnel separately with an SSH client.  

 

For example the mongolite manual contains this example:

 

con <- mongo("mtcars", url = "mongodb://readwrite:test@ds043942.mongolab.com:43942/jeroen_test")

  

Assume we want to tunnel through dev.opencpu.org which runs an SSH server on the standard port 22 with username jeroen. To initiate a tunnel from localhost:9999 to ds043942.mongolab.com:43942 via the ssh server dev.opencpu.org:22, open a terminal and run:

 

ssh -L 9999:ds043942.mongolab.com:43942 jeroen@dev.opencpu.org -vN -p22

  

At last, we can connect to our ssh client which tunnel traffic to MongoDB server. In this example we run the ssh client on localhost port 9999:

 

con <- mongo("mtcars", url = "mongodb://readwrite:test@localhost:9999/jeroen_test")

 

con$insert(mtcars)

 

For more information, please check : SSH Tunnel

 

Regards,

Pirlo Zhang

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 523 members 4,310 guests
Please welcome our newest community members: