I've installed mongodb and have been able to run it, work with it, do simple DB read / write type stuff. Now I'm trying to set up my Mac to run mongod as a service.
I get "Command not found" in response to:
init mongod start
In response to:
~: service mongod start
service: This command still works, but it is deprecated. Please use launchctl(8) instead.
service: failed to start the 'mongod' service
And if I try:
~: launchctl start mongod
launchctl start error: No such process
So obviously I'm blundering around a bit. Next step seems to be typing in random characters until something works. The command which does work is: mongod --quiet &
I'm not sure, maybe that is the way you're supposed to do it? Maybe I should just take off 'quiet mode' and add > /logs/mongo.log
to the end of the command line?
I'm building a development environment on a Mac with the intention of doing the same thing on a linux server. I'm just not sure of the Bash commands. All the other searches I do with trying to pull up the answer give me advice for windows machines.
Perhaps someone knows the linux version of the commands?
Thanks very much
mongod
wasn't working to start the daemon for me but after I ran the following, it started working:(from here: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/)
With recent builds of mongodb community edition, this is straightforward.
When you install via brew, it tells you what exactly to do. There is no need to create a new launch control file.
On macOS 10.13.6 with MongoDB 4.0
I was unable to connect to localhost from the mongo shell
I started MongoDB with:
I found that the 'mongod.conf' had:
Change my JavaScript connection from localhost to 127.0.0.1 and it worked fine.
The same was occurring with MongoDB Compass too.
Edit: you should now use
brew services start mongodb
, as in Gergo's answer...When you install/upgrade mongodb, brew will tell you what to do:
It works perfectly.
Just installed MongoDB via Homebrew. At the end of the installation console, you can see an output as follows:
To start mongodb:
Or, if you don't want/need a background service you can just run:
So, brew services start mongodb, managed to run MongoDB as a service for me.
Homebrew's
services
tap integrates formulas with thelaunchctl
manager. Adding it is easy:You can then launch MongoDB with this command (this will also start mongodb on boot):
You can also use
stop
orrestart
: