What is the correct way to start a mongod service on linux / OS X?
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.
$ brew install mongodb
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.0.6.yosemite.bottle.tar.gz ### 100.0%
==> Pouring mongodb-3.0.6.yosemite.bottle.tar.gz
==> Caveats
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
/usr/local/Cellar/mongodb/3.0.6: 17 files, 159M
Start mongod service at system startup
You can either put the command in your /etc/bashrc script under and if condition i.e. if the mongod process is not already running, then start it.
Other way is to modify your /etc/rc.local and add the command to start mongod in that file. It will start at bootup.
Mongod service won't start in OSX
Create a folder somewhere in your drive and start it using
mongod --dbpath yourfolder --logpath myfile.log --logappend
.. and check the result.
I have several instances of mongo running in my Mac with Maverick OSX and it works perfectly.
I think it's the best way to test it. After that you can review what's going on with the config files.
If this works you can add --fork at the end to fork the process.
Installing and Running MongoDB on OSX
Assuming you have created the data/db directory under bin after install.
- Start a terminal for your mongo server
- Go to
<mongodb-install-directory>/bin
directory Run the command
./mongod
Start a terminal for your mongo shell
- Go to
<mongodb-install-directory>/bin
directory Run the command (make sure you put the name of the database)
./mongo test
MongoDB start error
mongo
is the client shell, it's not a server. You start a MongoDB server with the mongod
command. For example:
mongod --dbpath ~/mongodb/data
You can also start mongod
automatically when your OS starts up. You can find instructions here: https://stackoverflow.com/a/17061202/236660
After the server is started, you can use mongo
to connect to the server.
Note that you can also run the mongo shell without connecting to any server:
mongo --nodb
Of course, you won't be able to do much with just the shell.
Related Topics
How to Read Single Character Input from Keyboard Using Nasm (Assembly) Under Ubuntu
Grep Inside All Files Created Within Date Range
Remove a Symlink to a Directory
How to Get the Resolution (Width and Height) for a Video File from a Linux Command Line
Best Way to Get MAChine Id on Linux
Syntax Error Near Unexpected Token 'Then'
Using Ls to List Directories and Their Total Sizes
Why Child Process Still Alive After Parent Process Was Killed in Linux
Prevent Gnome Terminal from Exiting After Execution
Grep Without Showing Path/File:Line
Pthread Mutex Lock Unlock by Different Threads
Best Way to Find Os Name and Version in Unix/Linux Platform
What Is Path on a MAC (Unix) System
Write a Bash Shell Script That Consumes a Constant Amount of Ram for a User Defined Time