I am trying to install MONGODB, followed a bunch of tutorials and haven't had luck. Prior to this, when I typed mongo in the terminal, it would say it wasn't found. However I stumbled upon https://www.mongodb.com/community/forums/t/unable-to-connect-to-mongo-shell-error-connecting-to-127-0-0-1-27017-caused-by-connection-refused-connect-src-mongo-shell-mongo-js13/89945/2 and copied
>mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/100YWeatherSmall?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics
into my terminal. I want to restart fresh and get rid of everything related to mongo. However, even after following the instructions from https://www.mongodb.com/basics/uninstall-mongodb for mac, I can't seem to restart fresh. I seem to get
MongoDB shell version v5.0.9
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
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:372:17
#(connect):2:6
exception: connect failed
exiting with code 1
My problem is that I am having trouble installing MongoDB and ended up blindly copying something. Now I can't seem to go back to the original message where after I type mongo, it would give the message saying it wasn't found. Instead, I get the message that I mentioned above. Any ideas on how to fix this? Thanks!
You may want to try these commands to repair and restart your mongodb server:
1) Remove .lock file
sudo rm /var/lib/mongodb/mongod.lock
2) repair the mongodb
mongod -–repair
3) start the mongod server
sudo service mongod start
4) start the mongo client
mongo
.> mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] Socket recv() An established connection was aborted by the software in your host machine. 127.0.0.1:27017
2018-06-26T17:37:13.313+0530 I NETWORK [thread1] SocketException: remote: (NONE):0 error: SocketException socket exception [RECV_ERROR] server [127.0.0.1:27017]
2018-06-26T17:37:13.313+0530 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
This problem can happen when trying to connect to a database which requires SSL.
This error is usually caused by attempting to connect without SSL to a MongoDB server that requires it. Use the following command to connect:
mongo --ssl --username "$USERNAME" --password "$PASSWORD" --host "$HOST" --port "$PORT"
See Mongod logs to find the root cause. For me it was leaking connections from one of the clients, this is what I found in logs:
NETWORK [listener] connection refused because too many open connections:
(SSL causing the issue)
You can connect with it using this command :
mongo --host 127.0.0.1:27017 --tls --username fake --password fakepassword --authenticationDatabase admin --sslAllowInvalidHostnames
Disables the validation of the hostnames in TLS/SSL certificates.
Allows mongo to connect to MongoDB instances even if the hostname in
their certificates do not match the specified hostname.
Deprecated since version 4.2: Use --tlsAllowInvalidHostnames instead.
WARNING :
Although available, avoid using the --sslAllowInvalidCertificates
option if possible. If the use of --sslAllowInvalidCertificates is
necessary, only use the option on systems where intrusion is not
possible.
If mongosh (and other MongoDB Tools) runs with the
--sslAllowInvalidCertificates option, mongosh (and other MongoDB Tools) will not attempt to validate the server certificates. This
creates a vulnerability to expired mongod and mongos certificates as
well as to foreign processes posing as valid mongod or mongos
instances. If you only need to disable the validation of the hostname
in the TLS/SSL certificates, see --sslAllowInvalidHostnames.
See MongoDB official Doc
just go simply on task manager and click on service
see given image below to copy the link on the URL
find MongoDB and click on open Service.
see given image below to copy the link on the url
then again find MongoDB and start stopped DB to running mode just click on green point button and you MongoDB is again started connecting.
[see given image below to copy the link on the url]
In my case , I was running several applications on other ports. The above solutions did not worked well for me .
Finally I closed all the tabs of code editor and web-app , and restarted it . Now it works fine .
Well! You can just restart the system, that will also work with least hassle.
As stated, this can happen because the server requires TLS in the connection. You will see the reason in server logs.
For someone who ends here without knowing how to fix it (like me) it's worth noting how to connect to those servers:
In command line you can use the --tls option (https://docs.mongodb.com/manual/tutorial/configure-ssl-clients/)
mongo --tls [other params and/or connection string]
If using a connection string alone, you can add tls=true param:
mongo://[user]:[pass]#[host]/[db]?tls=true[&others]
I was getting error in the mongod logs that read
WiredTiger metadata corruption detected
To fix the error I did the following:
As per suggestion here I ran command mongod --dbpath /data/db --repair.
The logs from command above complained that my version of mongod was too recent (I was on 4.2.x) and I had to try on mongod 4.2 or earlier.
Downgraded to mongod 4.2
Ran command mongod --dbpath /data/db --repair again, and this fixed issue.
I do run mongod inside Docker, so I had to take an extra step to find out path of the mongo DB file, docker inspect <id of mongod container>, and grab the path from the HostConfig.Binds[0] property of the resulting JSON, and stick that in the --dbpath option of the repair command mongod --dbpath /data/db --repair
In my case it is net.maxIncomingConnections: 10 in the config file and MongoDB Compass.
All available connection slots the server has, are consumed by other clients and that causes new connection requests to just drop.
I was not aware that Compass would open so many connections. When I closed it, my problem was solved.
The default connection limit is 65536 as stated in config options
I don't know why this happens but sometimes my mongo instance fails to start properly. Just shutting it down and restarting it worked for me.
I have issue with Mongo DB start up in ubuntu 14.04 64 bit,its working fine when i installed first time but suddenly from now when i type mongo in ubuntu terminal its showing error:
MongoDB shell version: 3.0.7
connecting to: test
2015-11-26T11:59:03.888+0530 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-11-26T11:59:03.889+0530 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
I tried many solution
i.e
1.deleting lock files, and restart mongo,
2.Change bind ip to 0.0.0.0 in mongod.conf
but my issue still not resolved.
Try to execute the following command to grep process id of mongod to determine if mongo service is running or not
pgrep mongod
If process id exists then please follow the steps as mentioned below
(a) Kill existing mongod process using following command
sudo kill -9 [process_id]
(b) Start mongod process using
sudo mongod --noauth --dbpath /var/lib/mongodb
I installed mongodb from this link
When i entermongo in console I got error
root#512son:~# mongo
MongoDB shell version: 2.6.9
connecting to: test
2015-04-10T05:35:23.837+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-04-10T05:35:23.838+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
I searched this problem on internet and i tried:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
If i enter mongod in terminal Mongodb work fine but when i close terminal mongodb is closing
I reinstall two times but my problem not fixed
You need to run MongoDB in the background. I mean start mongod as daemon using --fork
So I've got a virtual machine running on windows azure and installed mongoDB. However mongod works fine when I do: mongod --dbpath /mnt/datadrive/data but when I end the process and do mongo, I get:
2015-01-10T14:23:17.474+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-10T14:23:17.476+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
I've edited the config /etc/mongod.config however when I try and run sudo service mongo start I get:
Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.
What I'm initially trying to do is have mongoDB running as a service on my virtual machine so I can remotely can connect to it at anytime.
When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/Kyle-3/Desktop/DEV/dangerzonearea/test/mongodb
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!
Solution:
Don't end the service. Let it continue while you use mongo from another cmd or shell.