I'm trying to connect to a localhost database with mongodb-community 4.2.2, but I'm having connection refused:
MongoDB shell version v4.2.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-01-17T14:49:50.057+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
2020-01-17T14:49:50.060+0100 F - [main] exception: connect failed
2020-01-17T14:49:50.060+0100 E - [main] exiting with code 1
I don't know what is going on. I tried:
brew uninstall --force mongodb-community
rm -rf /homebrew.mxcl.mongodb-community.plist
rm -rf /Cellar/mongodb-community/ folder
brew update
brew install mongodb-community
And all kind of approaches, but nothing solved my problem...
Anyone can help?
If you install mongodb through brew, try running this command to start it:
mongod --dbpath /usr/local/var/mongodb
Try following these instructions: LINK
Then manually delete the content within /usr/local/var/mongodb.
Finally, restart the mongodb-community service.
Regards
To reconnect DB, just run the command that #user129916 suggested.
sudo mongod --dbpath /usr/local/var/mongodb
If the error is "Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied":
Delete the file:
/tmp/mongodb-27017.sock
Set the mongoDB configuration file:
mongod -f /usr/local/etc/mongod.conf
Set path to DB
sudo mongod --dbpath /usr/local/var/mongodb
For me the issue was caused by a combination of IPV6 and /tmp/mongodb-27017.sock permission after the update. I fixed it by completely removing mongo and the .sock reinstalling and also adding ipv6 to the config.
Steps below:
Completely remove mongodb-community
sudo rm -rf /usr/local/Cellar/mongodb-community
brew cleanup
Recreate mongodb directory
sudo rm -rf /usr/local/var/mongodb
cd /usr/local/var && mkdir mongodb
Remove /tmp/mongodb-27017.sock
cd /tmp
sudo rm -rf mongodb-27017.sock
Reinstall mongodb-community
brew install mongodb-community
brew services start mongodb-community
brew services list
Possibly optional. Needed to call restart since it had a permission error wanting sudo but it didn't like that and restart seemed to work without sudo
brew services restart mongodb-community
If your error says something like ... ECONNREFUSED ::1:27017 also add the following steps
Update mongod.conf to also accept IPV6
vi /usr/local/etc/mongod.conf or your preferred editor
Add
ipv6: true
bindIp: ::1, 127.0.0.1
Related
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.
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
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 am trying to connect to my MongoDB database in localhost. While I type mongo in command shell I am getting an error in the command shell:
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 :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:341:17
This will start the mongo server as a service:
brew services start mongodb-community
command mongod will run the MongoDB server using the default configuration. You can change these configurations by locating the default path of the configuration files.
The primary daemon process for the MongoDB database system is called mongod. You need to start this service before making connection attempts.
You can do this in Ubuntu by:
sudo service mongod start
or,
sudo systemctl start mongod
Start mongod on system boot by:
systemctl enable mongodb.service
I had the same issue.
When running mongod command, it mentioned the C:/data/db as E:/data/db path.
After I created the folder in mentioned E:/data/db path it works!
For windows user
1. Type ctrl + r
2. Scroll to mongodb server
3. start the server
do you have a linux distro? If you do, the solution is a bit annoying as you have to do it everytime you start your pc. The solution is:
Type "mongo" and "mongod" once in the terminal. It will show an error, don't worry, that's the whole point
type this:
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo service mongod restart
tip: copy the whole thing and paste on the terminal using ctrl+shift+v. You're welcome :-)
I first execute the command:
sudo service mongodb restart
I get the prompt:
stop: Unknown instance:
mongodb start/running, process 3175
Then,I execute the command:
mongo
I get the error:
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 8 19:48:08.961 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I don't know how I get this error.
Execute the following command
sudo rm -rf /var/lib/mongodb/mongod.lock
then
sudo service mongodb restart
Just Execute these following lines:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo start mongodb
sudo status mongodb
mongo
Now you can access to your mongo terminal.