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

前端 未结 26 2876
轻奢々
轻奢々 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: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
    

提交回复
热议问题