hhs
hhs

Reputation: 93

Error: couldn't connect to server 127.0.0.1:27017 even though I am running mongod

MongoDB shell version v4.2.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-05-02T19:00:36.477-0500 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-05-02T19:00:36.483-0500 F  -        [main] exception: connect failed
2020-05-02T19:00:36.483-0500 E  -        [main] exiting with code 1

That is the error that I am getting after running Mongo and this is the response that I get after running mongod

2020-05-02T19:00:34.303-0500 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] MongoDB starting : pid=3964 port=27017 dbpath=/data/db 64-bit host=Mateos-MBP.attlocal.net
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] db version v4.2.3
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] git version: 6874650b362138df74be53d366bbefc321ea32d4
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] allocator: system
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] modules: none
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] build environment:
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten]     distarch: x86_64
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten]     target_arch: x86_64
2020-05-02T19:00:34.309-0500 I  CONTROL  [initandlisten] options: {}
2020-05-02T19:00:34.310-0500 I  STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2020-05-02T19:00:34.310-0500 I  NETWORK  [initandlisten] shutdown: going to close listening sockets...
2020-05-02T19:00:34.313-0500 I  -        [initandlisten] Stopping further Flow Control ticket acquisitions.
2020-05-02T19:00:34.313-0500 I  CONTROL  [initandlisten] now exiting
2020-05-02T19:00:34.313-0500 I  CONTROL  [initandlisten] shutting down with code:100

I have looked at multiple other questions and still can't seem to figure it out any help would be appreciated.

Upvotes: 1

Views: 7866

Answers (4)

RENJITH V.S
RENJITH V.S

Reputation: 95

Open your task manager>services>MongoDB>"right-click and start the server"

Upvotes: 1

Moses Wangira
Moses Wangira

Reputation: 178

I followed this simple steps

Open your task manager if on windows 
go to services -> go to MongoDB on services list provided
left click to highlight then down below click
->open services
on the list provided find MongoDB server
left click to highlight
click on the green play button to start the mongoDbServer
wait for a while
run your command again it will work

Upvotes: 2

Suben Saha
Suben Saha

Reputation: 1848

Create a directory /data/db and give permission to the MongoDB user so that MongoDB can access it. To create the directory:

sudo mkdir -p /data/db

To change owner:

sudo chown -R $USER /data/db

Upvotes: 3

PatrickChen
PatrickChen

Reputation: 1420

It's obvious, that the MongoDB startup failed.

2020-05-02T19:00:34.310-0500 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating

That's why you can't connect it. Because it's never startup. You can try to fix the MongoDB startup issue, then try to log in through CMD to make sure it's ok.

Upvotes: -2

Related Questions