Launching MongoDB while our MAC starts
Once MongoDB is installed in our MAC OSX, the most useful is to launch the mongod service automatically when our computer is starting.
Steps to follow
These are the steps to follow:
- We must create the file org.mongodb.mongod.plist at the directory /Library/LaunchDaemons, with this content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.mongodb.mongod</string> <key>ProgramArguments</key> <array> <string>/path/to/your/mongod/binary/mongod</string> <string>run</string> <string>--config</string> <string>/path/to/your/mongodb.conf/file/mongodb.conf</string> </array> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>your_user</string> </dict> </plist> |
- Now we load the file
1 |
$ sudo launchctl load org.mongodb.mongod.plist |
Starting MongoDB manually
If we need to start, or stop, manually the daemon this would be the way:
1 2 |
$ sudo launchctl start org.mongodb.mongod $ sudo launchctl stop org.mongodb.mongod |
Creating the alias
Even, we can use aliases by editing the ~/.bash_profile file by this manner:
1 2 |
alias mongostart="launchctl start org.mongodb.mongod" alias mongostop="launchctl stop org.mongodb.mongod" |
Interesting links
These are the urls I have read for extracting the information above.
http://www.journaldev.com/2330/how-to-install-mongodb-on-mac-os-x-and-run-as-service
https://alicoding.com/how-to-start-mongodb-automatically-when-starting-your-mac-os-x/
I hope you find this post useful!
2 thoughts on “How to launch MongoDB while our MAC OSX starts”
Thank you @juan! With this I can setup my mac. Next I need to figure out how to configure my linux VM.
Hello Daniele. Glad to see you here!!!