Follow the instructions to install MongoDB, after that, run through the creation of the database. The default location is /data/db but if you’re using Macports to install, you can choose to install your database alongside mongodb in /opt/local/var/db/mongodb.
To start the mongo server, simply run mongodb. MongoDB doesn’t auto launch itself. To do so, we have to edit the plist and add it to LaunchDaemon.
This is based on a MacPorts installation. If you’re using Brew, your mileage might vary.
- Edit /Library/LaunchDaemons/org.macports.mongodb.plist. My plist file looks like this.
- sudo launchctl load /Library/LaunchDaemons/org.macports.mongodb.plist
- Restart your system
- Go back into terminal and run mongo. You should be able to get into the interactive Mongo shell directly.
To stop this auto-start behaviour, simply use the unload command like so: sudo launchctl unload /Library/LaunchDaemons/org.macports.mongodb.plist