MongoError: failed to connect to server [localhost:27017]

mongonetworkerror: failed to connect to server atlas
mongonetworkerror: failed to connect to server on first connect
mongodb failed to connect to localhost:27017
mongonetworkerror: failed to connect to server mlab
unhandledpromiserejectionwarning: mongonetworkerror: failed to connect to server
name: 'mongonetworkerror', errorlabels: ( 'transienttransactionerror)
unable to connect to mongodb failed to connect to localhost:27017, connection refused
mongonetworkerror: connection 0 to localhost:27017 timed out

When I type node server.js it returns me this error

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/home/islam/workspace/project/node_modules/mongoose/node_modules/mongodb-core/lib/topologies/server.js:327:35)
    at emitOne (events.js:96:13)
    at Pool.emit (events.js:191:7)
    at Connection.<anonymous> (/home/islam/workspace/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:274:12)
    at Object.onceWrapper (events.js:293:19)
    at emitTwo (events.js:106:13)
    at Connection.emit (events.js:194:7)
    at Socket.<anonymous> (/home/islam/workspace/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:177:49)
    at Object.onceWrapper (events.js:293:19)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:191:7)
    at emitErrorNT (net.js:1283:8)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)

**

When I type in command line mongod it returns me this

    2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] MongoDB starting : pid=24805 port=27017 dbpath=/data/db 64-bit host=user
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] db version v3.4.4
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] allocator: tcmalloc
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] modules: none
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] build environment:
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten]     distmod: ubuntu1604
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten]     distarch: x86_64
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten]     target_arch: x86_64
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] options: {}
2017-05-05T23:33:06.816+0600 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-05-05T23:33:06.816+0600 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-05-05T23:33:06.816+0600 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] now exiting
2017-05-05T23:33:06.816+0600 I CONTROL  [initandlisten] shutting down with code:100

**

However the mongo command gives me this error

 MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
2017-05-05T23:34:21.724+0600 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-05-05T23:34:21.724+0600 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

I need to access to my database collections,

Any help will be appreciated!


Mongo by default writes data to /data folder and the user who is running mongo service does not have permission to create /data folder.

You can get this information from this log snippet

2017-05-05T23:33:06.816+0600 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-05-05T23:33:06.816+0600 I NETWORK  [initandlisten] shutdown: going to close listening sockets...

So, you need to do this

sudo mkdir /data/db
sudo chown $USER -R /data/db # give permission to the user who is running mongo service

MongoError: failed to connect to server [localhost:27017], MongoDB connection error: MongoError: failed to connect to server [localhost:​27017] #1255. Open. gkatsanos opened this issue on Nov 21,  first run mongod.exe If it gives any warnings regarding unsafe shutdowns, metrics, diagnostics ignore them and run mongo.exe in another CLI(command line Interface).. Even then if it does not work, just backup the ../data/db directories and redo the database.


Looks like you need to create the /data/db folder

try doing this in the terminal

sudo mkdir /data/db

then start mongodb

MongoError: failed to connect to server [localhost:27017] on , Hi After "node main.js" i have this error** ubuntu@ip-10-0-1-57:/Rocket.Chat$ export MONGO_URL=mongodb://localhost:27017/rocketchat  I have paid membership and downloaded this project. After npm install and node app.js, it number, then use localhost:the_port_number in a browser


first run mongod.exe If it gives any warnings regarding unsafe shutdowns, metrics, diagnostics ignore them and run mongo.exe in another CLI(command line Interface).

Even then if it does not work, just backup the ../data/db directories and redo the database.

Before access the db using a database driver(eg: mongoose,mongojs) make sure that the database is up and running.

$ mongo MongoDB shell version v3.4.4 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.4 use YourAwesomeDatabaseName switched to db YourAwesomeDatabaseName

You are good to go!

Mongodb: failed to connect to server on first connect, Warning { MongoError: failed to connect to server [mongodb:27017] on first connect at Pool. mongoose.connect('localhost/users_test'); But not mongoose.connect('mongodb:localhost/users_test');it doesn't match the right  Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.


I had an issue /mongo.js:237:13 in local terminal trying to run GCP-hosted mongo. I fixed it by removing tags in GCP

Fix Node.js MongoError: failed to connect to server, Fix MongoError: failed to connect to server by verifying if the Mongo Daemon is up and you are connecting to : mongodb : //127.0.0.1:27017. Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.


hey there This is the issue because of your mongodb server is not running

you can verify this by

sudo service mongodb status

** you need to start the server by running command

sudo service mongodb start

Good Luck

Mongoerror: failed to connect to server localhost:27017 on first , Added port 27017 on security group page. running the command on the ec2 instance as node server.js Node: My mongo DB is outside my cloud instance i.e on  MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017] MongoError: failed to


MongoError: failed to connect to server [192.168.100.2:9001] on first , MongoError: failed to connect to server [192.168.100.2:9001] on first MONGO_URL='mongodb://martini-henry:123456@localhost:27017/  MongoDB connection error: MongoError: failed to connect to server [localhost:27017] #1255. gkatsanos opened this issue on Nov 21, 2017 · 53 comments. gkatsanos commented on Nov 21, 2017. I have a project which includes a docker setup that I'm trying to get working. My Dockerfile is: FROM node:8-alpine EXPOSE 3000 ARG NODE_ENV ENV NODE_ENV


MongoDB connection error: MongoError: failed to connect to server , Ask questions MongoDB connection error: MongoError: failed to connect to server [localhost:27017]. I have a project which includes a docker setup that I'm  GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. { MongoError: failed to


MongoDB Connection Error, Connection Error: { MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED  Tank you i have test your very good tutorial, so easy, now, i can use a docker image with MongoDB and DemocracyOS. I have this text, in red color, if you have the same best practice, step by step, i translate that in french.