My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
MongoDB remote connection - Getting connection refused error

MongoDB remote connection - Getting connection refused error

anuj tyagi's photo
anuj tyagi
·Mar 13, 2016

Application System IP: 10.0.0.15

MongoDB Server IP : 10.0.0.215

Here are a few details :

I'm running a Python web application on different system and mongo db on different system. Both systems can ping each other.

  • I have replaced socket ip to connect to mongo db from 127.0.0.1 to mongo db system ip.

  • Given MongoDB ip in application to connect but when running application I'm getting connection refused error.

  • Added MongoDB system private ip with localhost,127.0.0.1 to bind variable in /etc/mongod.conf bind_IP = 127.0.0.1, 10.0.0.215

  • Both systems are running on same network

  • Application working fine when running mongodb on localhost.
  • Do I need to make any changes in MongoDB client file dist-packages/pymongo/mongo_client.py also ?

Screenshot of error: https://i.imgsafe.org/a733a2d.png

/// database.py file

import pymongo

class Database(object):
    URI = "mongodb://127.0.0.1:27017"
    DATABASE = None

    @staticmethod
    def initialize():
        client = pymongo.MongoClient(Database.URI)
        Database.DATABASE = client['fullstack']

    @staticmethod
    def insert(collection, data):
        Database.DATABASE[collection].insert(data)