Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start / Stop MongoDB with Homebrew

I am using mac osx 10.10.5

This question has been asked many times before and after following the steps, I notice bizarre behavior.

These are the steps which I have taken

brew tap gapple/services
brew install mongodb

This installs the product and now when I do brew services list I can see mongodb in a stopped state.

When I tried to start the process by brew services start mongodb I get an error

Error: Could not read the plist for mongodb!

OK. I googled a solution

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/mongodb/3.0.6/homebrew.mxcl.mongodb.plist ~/Library/LaunchAgents/

Now as soon as the file is copied, when I do brew services list ... the mongo process is automatically running.

Now when I do brew services stop mongodb It says

Error: Service `mongodb` not running, wanna start it? Try `brew services start mongodb`

Now this is bizarre, because just in the last step it said its running. Now when I do

mongodb services list it says that the service is stopped. (so the stop command above did work. Even though it threw an error).

Now if I do

brew services start mongodb

It gives error Error: Could not read the plist for mongodb!

Now if I copy the file again

cp /usr/local/Cellar/mongodb/3.0.6/homebrew.mxcl.mongodb.plist ~/Library/LaunchAgents/

The service automatically begins to run.

I find this whole thing really bizarre. All I want is a clean way to start stop the mongo db service. And although there are many threads on this site (and elsewhere) ... they don't work or just have strange behavior.

like image 466
Knows Not Much Avatar asked Oct 06 '15 16:10

Knows Not Much


People also ask

How do I start and stop MongoDB?

To start the service use: NET START MONGODB. To stop the service use: NET STOP MONGODB.

How do I start MongoDB on Mac?

Run the Mongo daemon, in one terminal window run ~/mongodb/bin/mongod . This will start the Mongo server. Run the Mongo shell, with the Mongo daemon running in one terminal, type ~/mongodb/bin/mongo in another terminal window. This will run the Mongo shell which is an application to access data in MongoDB.

How do I start MongoDB from terminal?

Open the terminal, and navigate to your home directory: cd ~ . Then make a folder where all of the actual database data will go: mkdir -p mongodb/data/db . Now you're ready to start the server. To ensure that you have MongoDB installed correctly, run mongo --version and mongod --version .


2 Answers

brew services start/restart/stop [email protected]
like image 182
Abhilash Avatar answered Sep 24 '22 15:09

Abhilash


For me I had multiple version of mongodb and when I tried to switching between them, I got this error

Error: Could not read the plist for `mongodb26`!

This is what I did to start mongodb26 service.

brew unlink mongodb24
brew link mongodb26
brew services start mongodb26
like image 23
Trimal Avatar answered Sep 24 '22 15:09

Trimal