Pymongo keeps refusing the connection at 27017

前端 未结 9 706
灰色年华
灰色年华 2020-11-29 04:23

I am trying to run a simple connection to pymongo but it keeps returning that the connection was refused

Here is what I tried:

>>>from pymon         


        
相关标签:
9条回答
  • 2020-11-29 04:48

    For anyone who's having this problem on a remote server rather than the localhost, try enabling external interfaces:

    • Go to the configuration file (ex. /etc/mongodb.conf)
    • Find bind_ip=127.0.0.1
    • Comment out that line with a # at the front
    • Restart mongod
    0 讨论(0)
  • 2020-11-29 04:50

    Removing mongod.lock inside /var/lib/mongodb

    sudo rm /var/lib/mongodb/mongod.lock
    

    And then restarting the service should do it. For example, in my Ubuntu installation, restarting the server is something like this:

    sudo service mongodb start
    
    0 讨论(0)
  • 2020-11-29 04:55

    For the newer versions(4.x) of MongoDb, you can try:

    sudo rm /var/lib/mongodb/mongod.lock

    sudo systemctl daemon-reload

    sudo systemctl start mongod

    0 讨论(0)
  • 2020-11-29 04:55

    First make sure you have installed mongodb using sudo apt install mongodb

    0 讨论(0)
  • 2020-11-29 04:56

    Try following commands :

    sudo service mongod start
    sudo service mongod status
    

    db.py

    import pymongo
    from pymongo import MongoClient
    #mongo client is connected
    client = MongoClient()
    db     = client['db']
    
    0 讨论(0)
  • 2020-11-29 04:58

    If you're trying to connect from a server (other than your localhost), try checking if your mongo installation is complete : you should have: * /var/lib/mongodb file * /var/log/mongodb file * mongodb.service as service ( check by starting the service sudo service mongodb start )

    If any of those fails, try reinstalling mongo ( Failed to start mongod.service: Unit mongod.service not found )

    This solved my problem. Cheers

    0 讨论(0)
提交回复
热议问题