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

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

    My problem was the wrong port number for mongoDB server.

    I had:

    DATABASE_URL= "mongodb://localhost:3000/node-express-mongodb-server"
    

    in my .env file (my environmental variables), but I had written it before running mongoDB server. So when I ran the mongoDB server, it wrote a different port number and I had to change it. I changed it to the right port number (which was written on my cmd window by mongoDB):

    DATABASE_URL= "mongodb://localhost:27017/node-express-mongodb-server"
    

    and now it works fine.

提交回复
热议问题