MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]

前端 未结 26 2501
轻奢々
轻奢々 2020-11-30 04:34

I\'m new in nodeJS, started learning by following a trailer on youtube, everything goes well until I added the connect function if mongodb,

mongo.connect(\"m         


        
相关标签:
26条回答
  • 2020-11-30 04:55

    this might help someone if you installed your mongo on .msi setup kindly open the software and select repair instead of install and try again, that works for me .

    0 讨论(0)
  • 2020-11-30 04:57

    You have to install MongoDB database server first in your system and start it.

    Use the below link to install MongoDB

    https://docs.mongodb.com/manual/installation/

    0 讨论(0)
  • 2020-11-30 04:57

    1) If you haven't installed mongodb, install it.

    2) open a new terminal, type "mongo". This is going to connect you to a MongoDB instance running on your localhost with default port 27017:

    0 讨论(0)
  • 2020-11-30 04:58

    Your firewall blocked port 27017 which used to connect to MongoDB.

    Try to find which firewall is being used in your system, e.g. in my case is csf, config file placed at

    /etc/csf/csf.conf
    

    find TCP_IN & TCP_OUT as follow and add port 27017 to allowed incoming and outgoing ports

    # Allow incoming TCP ports
    TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995,2222,27017"
    
    # Allow outgoing TCP ports
    TCP_OUT = "20,21,22,25,53,80,110,113,443,587,993,995,2222,27017"
    

    Save config file and restart csf to apply it:

    csf -r
    
    0 讨论(0)
  • 2020-11-30 05:00

    I faced same issue but after a lot of RND. I found that whts the problem so run this command on your terminal.

    sudo service mongod start

    then run mongo on terminal

    0 讨论(0)
  • 2020-11-30 05:02

    Following the logic behind @CoryM's answer above :

    After trying EVERY solution google came up with on stack overflow, I found what my particular problem was. I had edited my hosts file a long time ago to allow me to access my localhost from my virtualbox.

    Removing this entry solved it for me...

    I had edited my hosts file too for Python Machine Learning setup 2 months ago. So instead of removing it because I still need it, I use 127.0.0.1 in place of localhost and it worked :

    mongoose.connect('mongodb://127.0.0.1/testdb')
    
    0 讨论(0)
提交回复
热议问题