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

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

    If the mongoDB server is already installed and if you are unable to connect from a remote host then follow the below steps,

    Login to your machine, open mongodb configuration file located at /etc/mongod.conf and change the bindIp field to specific ip / 0.0.0.0 , after that restart mongodb server.

        sudo vi /etc/mongod.conf
    
    • The file should contain the following kind of content:

        systemLog:
            destination: file
            path: "/var/log/mongodb/mongod.log"
            logAppend: true
        storage:
            journal:
                enabled: true
        processManagement:
            fork: true
        net:
            bindIp: 127.0.0.1  // change here to 0.0.0.0
            port: 27017
        setParameter:
            enableLocalhostAuthBypass: false
      
    • Once you change the bindIp, then you have to restart the mongodb, using the following command

        sudo service mongod restart
      
    • Now you'll be able to connect to the mongodb server, from remote server.

提交回复
热议问题