Setting read/write permissions on Mongodb folder

Zoltan King picture Zoltan King · Mar 11, 2015 · Viewed 36.7k times · Source

I just finished installing MongoDB on OSX and setup a directory structure with sudo mkdir -p /data/db.

When I attempt to run mongod from my user account it returns an error stating that my user account does not have read/write permission to /data/db.

How can I set the proper read/write permissions on my account for /data/db?

Answer

davidcondrey picture davidcondrey · Mar 12, 2015

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