. Advertisement .
..3..
. Advertisement .
..4..
Hello, everyone.
I’m very tired of the ”mongoerror: failed to connect to server [localhost:27017] on first connect” because I’ve been thinking for some days but still haven’t found any solutions for it.
I was running this program:
[email protected]:~/workspace/nodejs/mongodb$ mongo
MongoDB shell version v3.4.9
connecting to: mongodb://127.0.0.1:27017
2017-10-30T14:32:21.476+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-10-30T14:32:21.477+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
[email protected]/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed
Suddenly I got a warning message:
Mongoerror: failed to connect to server [localhost:27017] on first connect
I didn’t know the cause of this error. Does anyone have suggestions and share them with me? Thanks!
Hi, Shanestrackejr! Don’t be stressful. I am here to help you!!!
The cause:
The server cannot connect to the MongoDB because your MongoDB Service is not started.
Solution:
To solve this error, you have to activate MongoDB Service. You can do as the following:
At the time Service is started, the Mongo Shell is also activated:
MongoDB records the URL in the terminal when Mongo Shell is launched, looks like the base of URL below:
Finally, let’s check carefully whether you provide the similar base URL or the same Port and IP for your Node.js Application or not by doing: