1

Steps:

brew update
brew install mongodb
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
mongo

Output:

MongoDB shell version: 3.2.4
connecting to: test
2016-04-12T20:53:47.253+0100 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2016-04-12T20:53:47.253+0100 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:224:14
@(connect):1:6

exception: connect failed

As per Can't start mongodb by launchctl on OS X Yosemite (10.10.2) I also tried:

brew tap gapple/services
brew services start mongodb

But got the same problem. However if I just do

mongod

and then in another shell, it works fine:

mongo
MongoDB shell version: 3.2.4
connecting to: test
> 
tdc
  • 115
  • 10

2 Answers2

1

I had a similar issue and this helped me:

#!/usr/bin/env sh

# checks to see if running 
launchctl list | grep mongo

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl remove homebrew.mxcl.mongodb

pkill -f mongod

rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

brew uninstall mongodb

# double check existence
ls -al /usr/local/bin/mong*
ls -al ~/Library/LaunchAgents

rm -R /usr/local/var/mongodb

Also see my answer here: https://stackoverflow.com/questions/41913838/installed-docker-and-ran-a-container-with-mongodb-now-brews-mongodb-isnt-work/41943399#41943399

timhc22
  • 113
  • 5
1

I try several times to solve this problem here in my machine, so I found the correct solution: here

Especial thanks to @gorjanz.