Mongodb Couldn't connect to local server - mongodb

When I tried to connect to Mongodb locally, following error occurred.
MongoDB shell version v3.6.4
connecting to: mongodb://127.0.0.1:27017
2018-05-07T21:34:02.181+0545 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2018-05-07T21:34:02.181+0545 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I went through some solution in the internet and some of them told that try to run mongod first in one terminal and after that run mongo in another terminal. I'm using windows and I did this process in my command prompt.
When I tried to run mongod at first then following error is encountered -
2018-05-07T08:53:18.307-0700 I CONTROL [initandlisten] MongoDB starting : pid=4964 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-8E9NTFH
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] db version v3.6.4
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] git version: d0181a711f7e7f39e60b5aeb1dc7097bf6ae5856
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips 27 Mar 2018
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] allocator: tcmalloc
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] modules: none
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] build environment:
2018-05-07T08:53:18.308-0700 I CONTROL [initandlisten] distmod: 2008plus-ssl
2018-05-07T08:53:18.309-0700 I CONTROL [initandlisten] distarch: x86_64
2018-05-07T08:53:18.309-0700 I CONTROL [initandlisten] target_arch: x86_64
2018-05-07T08:53:18.309-0700 I CONTROL [initandlisten] options: {}
2018-05-07T08:53:18.309-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2018-05-07T08:53:18.309-0700 I CONTROL [initandlisten] now exiting
2018-05-07T08:53:18.309-0700 I CONTROL [initandlisten] shutting down with code:100
I tried to uninstall and reinstall mongodb but it get stocked here. Need your help.

Mongod does not start because the data path does not exist or is not accessible.
exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found
Creating the directory should fix the issue.

Related

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.
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
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
Open your task manager>services>MongoDB>"right-click and start the server"
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.

MongoDB / Mongod on ubuntu vps 'Connection refused' error after creating ssh key

I created an ssh key for my vps today. When I then restarted the vps and tried running 'mongo' or 'mongod' im getting these errors:
For mongo:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2019-12-08T18:14:02.345+0100 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
2019-12-08T18:14:02.347+0100 F - [main] exception: connect failed
2019-12-08T18:14:02.347+0100 E - [main] exiting with code 1
For Mongod:
2019-12-08T18:09:50.619+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS
1.0 specify --sslDisabledProtocols 'none'
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] MongoDB starting : pid=1169 port=27017
dbpath=/data/db 64-bit host=1cc0f81c.cus9089.kvm.st-srv.eu
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] db version v4.2.1
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] git version:
edf6d45851c0b9ee15548f0f847df141764a317e
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1b 26 Feb 2019
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] allocator: tcmalloc
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] modules: none
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] build environment:
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] distmod: ubuntu1804
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] distarch: x86_64
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] target_arch: x86_64
2019-12-08T18:09:50.623+0100 I CONTROL [initandlisten] options: {}
2019-12-08T18:09:50.623+0100 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath:
Data directory /data/db not found., terminating
2019-12-08T18:09:50.623+0100 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2019-12-08T18:09:50.623+0100 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-
27017.sock
2019-12-08T18:09:50.623+0100 I - [initandlisten] Stopping further Flow Control ticket
acquisitions.
2019-12-08T18:09:50.624+0100 I CONTROL [initandlisten] now exiting
2019-12-08T18:09:50.624+0100 I CONTROL [initandlisten] shutting down with code:100
System-info: Ubuntu 19.04
What can I do to fix this and make it work again without losing my data?
I solved it by going over the installation steps again: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
This somehow solved it and now its working

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed mongodb [duplicate]

This question already has answers here:
Mongo is unable to start
(8 answers)
mongo - couldn't connect to server 127.0.0.1:27017
(46 answers)
Mongod complains that there is no /data/db folder
(28 answers)
Closed 3 years ago.
MongoDB is not connecting to my nodejs app earlier it was working fine but I don't know why this is not working when tried to run using shell I get this error
C:\Users\adity>mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2019-04-20T09:25:45.799+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2019-04-20T09:25:45.802+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I followed this answer to which I found in StackOverflow this is the link but it still gives the same error.
Anyone please help me to fix this.
while trying to start mongod i get this
C:\Users\adity>mongod
2019-04-19T21:12:16.552-0700 I CONTROL [initandlisten] MongoDB starting : pid=8888 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-H4VG30N
2019-04-19T21:12:16.552-0700 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-04-19T21:12:16.555-0700 I CONTROL [initandlisten] db version v3.6.5
2019-04-19T21:12:16.558-0700 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2019-04-19T21:12:16.558-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips 27 Mar 2018
2019-04-19T21:12:16.559-0700 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-19T21:12:16.559-0700 I CONTROL [initandlisten] modules: none
2019-04-19T21:12:16.560-0700 I CONTROL [initandlisten] build environment:
2019-04-19T21:12:16.560-0700 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-04-19T21:12:16.561-0700 I CONTROL [initandlisten] distarch: x86_64
2019-04-19T21:12:16.562-0700 I CONTROL [initandlisten] target_arch: x86_64
2019-04-19T21:12:16.562-0700 I CONTROL [initandlisten] options: {}
2019-04-19T21:12:16.566-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2019-04-19T21:12:16.569-0700 I CONTROL [initandlisten] now exiting
2019-04-19T21:12:16.569-0700 I CONTROL [initandlisten] shutting down with code:100

How to fix mongodb Error: Network is unreachable

I get this error, when I try to connect to MongoDB
Error:
Network is unreachable.
Running mongod before mongo shell didn't help .
When I restart my computer it works!!!Anyway I get that error again, something like 30 minutes later.
This is output from cmd, when I run command mongod
C:\Program Files\MongoDB\Server\4.0\bin>mongod
2019-04-26T18:50:26.559+0400 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-04-26T18:50:26.562+0400 I CONTROL [initandlisten] MongoDB starting : pid=1092 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-47AK9D5
2019-04-26T18:50:26.562+0400 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-04-26T18:50:26.563+0400 I CONTROL [initandlisten] db version v4.0.7
2019-04-26T18:50:26.563+0400 I CONTROL [initandlisten] git version: 1b82c812a9c0bbf6dc79d5400de9ea99e6ffa025
2019-04-26T18:50:26.564+0400 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] modules: none
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] build environment:
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-04-26T18:50:26.566+0400 I CONTROL [initandlisten] distarch: x86_64
2019-04-26T18:50:26.566+0400 I CONTROL [initandlisten] target_arch: x86_64
2019-04-26T18:50:26.567+0400 I CONTROL [initandlisten] options: {}
2019-04-26T18:50:26.568+0400 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2019-04-26T18:50:26.568+0400 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2019-04-26T18:50:26.568+0400 I CONTROL [initandlisten] now exiting
2019-04-26T18:50:26.568+0400 I CONTROL [initandlisten] shutting down with code:100
Edit: I found a problem. MongoDB Server turns off automatically. Just change service startup type to Manual.
MongoDB Server Properties

can't start mongodb on ubuntu

I've just installed mongodb on ubuntu using these instructions:
https://askubuntu.com/questions/724749/install-mongo-3-2-on-ubuntu-15-10
When I try to start it, I see this error:
me#devbox:/usr/bin$ service mongod start
Failed to start mongod.service: Unit mongod.service is masked.
me#devbox:~$ mongod
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] MongoDB starting : pid=4343 port=27017 dbpath=/data/db 64-bit host=mydev
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] db version v3.2.5
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] git version: 34e65e5383f7ea1726332cb175b73077ec4a1b02
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2d 9 Jul 2015
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] allocator: tcmalloc
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] modules: none
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] build environment:
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] distmod: ubuntu1404
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] distarch: x86_64
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] target_arch: x86_64
2016-04-15T11:24:01.941-0400 I CONTROL [initandlisten] options: {}
2016-04-15T11:24:02.031-0400 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-04-15T11:24:02.031-0400 I CONTROL [initandlisten] dbexit: rc: 100
When i try to check status, it says this:
me#devbox:~$ service mongod status
● mongod.service
Loaded: masked (/lib/systemd/system/mongod.service; masked; vendor preset: enabled)
Active: inactive (dead)
And when I try to start command line it says this:
me#devbox:/usr/bin$ mongo
MongoDB shell version: 3.2.5
connecting to: test
2016-04-15T11:32:11.828-0400 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-04-15T11:32:11.828-0400 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Not sure how to get this started