8

I am currently on OS/X using macbook. I want to stop the instance of mongodb service running. Hence I tried:

> sudo service mongodb stop
sudo: service: command not found

After looking up on Google, they asked me to add PATH hence I did the following:

> `vim ~/.bash_profile` (created a new bash_profile) and added the following there:

   export PATH=/usr/bin:/usr/sbin:/bin:/usr/local/bin:/sbin:/opt/x11/bin:$PATH

It does not seem to work and I still get the same error:

0

2 Answers 2

9

There is no service command on OS X. It's probably being managed by launchd which means you'll need to do the following (found on Stack Overflow). Note that there are 2 answers below, one if you installed using home-brew the other not.

It's probably because launchctl is managing your mongod instance. If you want to start and shutdown mongod instance, unload that first:

launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist

Then start mongod manually:

mongod -f path/to/mongod.conf --fork

You can find your mongod.conf location from ~/Library/LaunchAgents/org.mongodb.mongod.plist.

After that, db.shutdownServer() would work just fine.

Added Feb 22 2014:

If you have mongodb installed via homebrew, homebrew actually has a handy brew services command. To show current running services:

brew services list

To start mongodb:

brew services start mongodb

To stop mongodb if it's already running:

brew services stop mongodb

2
  • "brew services" command does not exist for me: $ brew services Error: Unknown command: services
    – Nicodemuz
    Apr 15, 2015 at 12:44
  • 1
    To install brew services: $ brew tap homebrew/services Then, install a formula as usual: $ brew install mongo You may now start/stop formula a service: $ brew services start mongo $ brew services stop mongo More info at github.com/Homebrew/homebrew-services Jun 5, 2015 at 16:27
0

These commands save my day thanks in advance.

To start mongodb:

brew services start mongodb

To stop mongodb if it's already running:

brew services stop mongodb
2
  • Hi, welcome on the Unix SE! These are two different commands. The OP wants to start/stop mongodb, but also he wants to know, why the "service" commands don't work for him. Its probably reason, that he read these on some Unix/Linux docs, and macosx is a little bit different. Give more explanation in your answers, so you will get more upvotes.
    – peterh
    Jun 1, 2018 at 20:25
  • if brew services start mongodb not work please try this command: sudo services start mongodb To stop mongodb if it's already running: brew services stop mongodb if this command not work please try this one : sudo services stop mongodb
    – SHOEB KHAN
    Oct 18, 2018 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.