Set up MongoDB in less than five minutes
I had some trouble setting up mongoDB when I was looking at the docs. In this post, I want to share how I set up mongoDB on my computer. Let’s still follow the guide because it does a great job.
- First, install Homebrew. Homebrew is a package manager that makes your life easier when you want to install packages in OSX.
Run this to install Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2 ) After installing Homebrew, let’s install mongoDB.
brew install mongodb
3) All mongo processes are stored in /data/db by default but you can specify your own dbpath but let’s do data/db first. In the docs, it says:
mkdir -p /data/db
but you need to do because you need to be the super user for access
sudo mkdir -p /data/db
Now we can try running mongod, which is the primary daemon process for the mongoDB.
Daemon is basically a background process that keeps running when you start it. It listens to requests, changes, and errors.
mongod
You might get this error because of permission issues
[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Don’t worry. You can open mongod.lock by giving access to the $USER
sudo chown -R $USER /data/db
Now run mongod again.
BOOM! Super easy set up. Now you can go to a mongo shell and do some cool things.
.