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?
Try following these instructions: LINK
Then manually delete the content within /usr/local/var/mongodb .
Finally, restart the mongodb-community service.
Regards
If you install mongodb through brew, try running this command to start it:
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:
sudo rm -rf /usr/local/Cellar/mongodb-community
brew cleanup
sudo rm -rf /usr/local/var/mongodb
cd /usr/local/var && mkdir mongodb
cd /tmp
sudo rm -rf mongodb-27017.sock
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 sudobrew services restart mongodb-community
If your error says something like ... ECONNREFUSED::1:27017
also add the following steps
vi /usr/local/etc/mongod.conf
or your preferred editor ipv6: true
bindIp: ::1, 127.0.0.1
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.