Having trouble installing/uninstalling MONGODB - mongodb

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

Related

Running `mongo` in the command line is giving error

I am trying to start a MERN app, I have installed mongo and any relevant things. But when I run mongo in my terminal the following appears.
I have looked across the board but the solutions do not help me. I am also running on Ubuntu 20.04.
MongoDB shell version v4.4.3
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:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
Fixed the issue by running
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo service mongod start
Try to start the MongoDB server first running mongod command or from task manager>services> MongoDB server> right-click and start it
Read this Document for more

error mongo without mongod running first locally in win 10

I have this mongo.zip installed in my win 10.
I have set the environment path with bin.
Somehow whenever I start command line,
my mongo cannot start without mongod first.
C:\Users\asus>mongo
MongoDB shell version v4.4.1
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 :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
but if I run mongod before mongo, mongo is running perfectly.
So, my question is: how do I running mongo without mongod locally.
PS. my compass is running and can connect to AWS cloud.
Please provide pictures if you can.
Thank you!
I think you, first of all, you have to know about the difference between them.
Mongod is the process of MongoDB.
Mongo is a shell. You can use it to connect and run any mongo command on any MongoDB.
So, your error means;
You are trying to connect your own MongoDB with typed mongo, because the default -host parameter is localhost. But your mongod process is not running. So you have to start it.
connecting to: mongodb://127.0.0.1:27017
127.0.0.1:27017 equals localhost.
If you have MongoDB (mongod process) on AWS. You should connect with below command
mongo --host mongodb0.example.com:28015

mongodb Network is unreachable on mac

Sorry I have ask the same question again from Robo 3T Error : Network is unreachable
Beacause I really can't find out the file /etc/mongod.conf.
My machine is mac and use homebrew install mongodb.
There is no mongod.conf in my path /usr/local/var/mongodb.
Any help would be appreciated.
According suggestion the path /usr/local/opt/mongodb/mongod.conf
My /usr/local/opt like this:
Try brew uninstall mongo and brew install mongo.
Connect it still get the same error.
But find the file mongod.conf in the path /usr/local/etc.
I try to remove the file and restart mongodb server then type command mongo get the error:
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-09-18T14:38:21.241+0800 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:257:13
#(connect):1:6
exception: connect failed
It is so strange...:(
You can create the mongod.conf at any folder on your Mac you like and pass the path to this file during the start of the Mongo DB server like:
mongod -f /path/to/mongod.conf
You have to create the mongod.conf manually e.g. on the desktop of your Mac. You can do this with the following commands.
Open a terminal
$ cd Desktop
$ touch mongod.conf
Then open the created (currently empty file) with a text editor of your choice and fill in your configurations (Here you can find a manual for the config file: https://docs.mongodb.com/manual/reference/configuration-options/)
Then start your Mongo DB server with
$ mongod -f /Users/YOUR_USERNAME/Desktop/mongod.conf
Please replace YOUR_USERNAME with your MacOs username you are currently working with

Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017'

.> 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.

Error in mongo start

i am using mongo 3.0.2 version
suddenly, i have got a problem in mongodb. Till yesterday mongodb is running fine. but today when i start mongo then it gives the following error.
2015-04-29T10:57:47.732+0530 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-04-29T10:57:47.733+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 have checked on internet. deleted the mongo lock file. but didn't resolve the problem yet.
when i check the service is show waiting and after start it doen't start as
service mongod status
mongod stop/waiting
sudo service mongod start
mongod start/running, process 2520
service mongod status
mongod stop/waiting
and anyone help to solve it out and explain why this problem occur.
I had the same issue and I managed to start mongod following those steps
1) mkdir data
2) cd data
3) mongod -dbpath .
Use this command, it works fine:
sudo mongod --config /etc/mongod.conf --fork
Try using sudo mongo to connect
Please make sure if port 27017 is already opened and didn't used by any application. You can check it with netstat command
Can you check whether port already used or not?
Below attaching link of similar issue:
Connection refused to MongoDB errno 111
Still problem persist then let me know.
check in the log file /var/log/mongodb/mongodb.log. I also got the same issue but due to lack of disk space.
exception in initAndListen: 15926 Insufficient free space for journals, terminating
Delete mongod.lock file in
data/db/mongod.lock
Then Run Again It Works Fine :)