Setting read/write permissions on Mongodb folder
Ensure that user account running mongod
has the proper directory permissions. You can check which permissions are set like so:
ls -ld /data/db/
If they are set properly they should look something like this..
drwxr-xr-x X user wheel XXX Date Time /data/db/
If the permissions are set incorrectly you will likely see an error similar to this when attempting to run mongod
exception in initAndListen: XXXXX Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
To get the permissions set as they should be you can run the following command
sudo chmod 0755 /data/db && sudo chown $USER /data/db
sudo chmod 777 /data/db/
Should work on Mac. Before running this cmd, permissions look like
drwxr-xr-x X User wheel Date /data/db
after running the cmd
drwxrwxrwx X User wheel Date /data/db
This is what worked for me. I am using a Mac, although you could try if you're using windows.
sudo chmod 777 /data/db