Search code examples
pythonmongodbpymongo

Pymongo usage with vpn


I am kinda new to pymongo. Is there any possible way to connect to mongodb with the usage of the VPN, if I have server address, login and password of the vpn server?

I have googled, but didn't find anything useful.


Solution

  • Sure, here you could do it with the pymongo library

    import pymongo
    from pymongo import import MongoClient
    
    client = MongoClient('mongodb://MikhailZhokhov:password@mongo_server_ip:27017/')
    db = client['yourdatabase']
    collection = db['mycollection']
    result = collection.find_one({'name': 'Mikhail Zhokhov'})
    
    client.close()
    

    Modify the above code accordigly, notice that your VPN need to be properly setup before running this script