Remote access from Python script (MongoKit)

467 views
Skip to first unread message

Максим Ващук

unread,
Aug 7, 2013, 5:16:50 AM8/7/13
to mong...@googlegroups.com
I have mongodb running on a remote server. I can ssh to the remote server and connect to mongodb from the shell on the remote machine. However i have to connect to that mongodb instance from my python script. How can I get access to data in such a db and use it in my python script? 

I use MongoKit to work with mongodb. Is there a possible solution based on it?

Justinas Gulbinas

unread,
Aug 7, 2013, 9:13:01 AM8/7/13
to mong...@googlegroups.com
As I understand  you can't connect to remote machine directly.
You can create ssh tunnel and port forward one mongo db port.

on linux/mac it's done easily with ssh command and -L key:
ssh <remote_server_host> -L 27017:localhost:27017 -N -v

After this you can connect to remote db using 'localhost:27014'

Hope that helps

j.

On 2013 Rugp. 7, at 12:16, Максим Ващук <vaschu...@gmail.com> wrote:

I have mongodb running on a remote server. I can ssh to the remote server and connect to mongodb from the shell on the remote machine. However i have to connect to that mongodb instance from my python script. How can I get access to data in such a db and use it in my python script? 

I use MongoKit to work with mongodb. Is there a possible solution based on it?

--
 
---
You received this message because you are subscribed to the Google Groups "MongoKit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongokit+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

John Brodie

unread,
Aug 7, 2013, 11:57:21 AM8/7/13
to mong...@googlegroups.com
Can you get to mongo remotely on the command line?  `mongo host` should connect.  If that fails, there are likely networking issues.  You should be able to use MongoKit by doing something like
```
        connection = mongokit.Connection( 'hostname', 'port')
```
Check http://api.mongodb.org/python/current/api/pymongo/connection.html?highlight=connection#pymongo.connection for more details, mongokit.Connection is just a wrapper around that, and should use the same API.
Reply all
Reply to author
Forward
0 new messages