Connection refuse for mongo macos - mongodb

Whenever I try to execute the command mongo from my terminal, this errors pops up:
MongoDB shell version v4.4.0
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:362:17
#(connect):2:6
exception: connect failed
exiting with code 1
I've been following this tutorial in order to install mongo on my MacBook Pro and failed by creating the /data/db. Later, this other article appeared upon me. The second one orders me to run the next piece of code from my terminal:
mongo — dbpath /System/Volumes/Data/data/db
But the same error that I pasted at the begining appears.
Is there anything I can do to install and keep mongo running?
OS: macOS Catalina - 10.15.16
Thanks in advance!

Try to:
brew services start mongodb/brew/mongodb-community

For macOS user:
1、reinstall mongodb-community
brew uninstall mongodb-community
brew cleanup
brew install mongodb/brew/mongodb-community
2、config and start
sudo mongod --config /usr/local/etc/mongod.conf
brew services start mongodb-community

Related

$ mongosh gives MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017

I'm getting MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017 when trying to start mongo locally with $ mongosh.
$ mongosh
Current Mongosh Log ID: 636addb4****************
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
Some details: I killed some process at some point to try to stop mongo so I could run run-rs -v 4.0.0 --shell.
Since I had installed mongo with brew this worked
$ brew services stop mongodb-community
$ brew services start mongodb-community
$ mongosh
Mark sure mongod is running.You could start it manually if it is in your system environmental variables path by typing mongod in your terminal
mongod
Faced similar problem than after reinstalling the package helped to solve the problem.

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

Mongodb connection error whenever rebooting server

I am using aws and installed ubuntu server on aws ec2.
I installed mongodb on it.
When installing mongodb, it is working well.
But If i reboot server and try to connect mongod in termina. I am getting the following error.
MongoDB shell version v4.4.0
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:362:17
#(connect):2:6
exception: connect failed
exiting with code 1
So whenever reboot server, i have to execute the following command and then mongo is working again.
sudo systemctl stop mongod
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo systemctl start mongod
I think whenever reboot server, executing above command does not make sense.
If anyone have experienced, please help me.
Thanks.
After you setup the mongodb you usually would enable it, so that it starts after each reboot:
sudo systemctl enable mongod

I couldn't MongoDB Installation on Debian

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

Install mongodb on ubuntu with apt-get fails

I'm trying to install mongoDB on Ubuntu Server 14.04 with apt-get.
My command ist sudo apt-get install mongodb-org -y
After installation I'm trying to run sudo service mongod start
The output is mongod start/running, process 11977
Trying to get status sudo service mongod status prints out mongod stop/waiting
Trying to stop mongod sudo service mongod stop prints stop: Unknown instance:
When I type mongo in command line I get this
MongoDB shell version: 2.6.3
connecting to: test
2014-08-02T11:49:28.781+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-08-02T11:49:28.782+0200 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
What I'm doing wrong?
mongod is not running, thats why you cant connect. Before you run it as a service, just run mongod from the command line and see how it fails. Once you get it working, you can convert to a service.