mongodb Mongod complains that there is no /data/db folder

I am using my new mac for the first time today. I am following the get started guide on the up until the step where one creates the /data/db directory. btw, I used the homebrew route.

So I open a terminal, and I think I am at what you called the Home Directory, for when I do "ls", I see folders of Desktop Application Movies Music Pictures Documents and Library.

So I did a

mkdir -p /data/db

first, it says permission denied. I kept trying different things for half and hour and finally :

mkdir -p data/db

worked. and when I "ls", a directory of data and nested in it a db folder do exist.

then I fire up mongod and it complains about not finding data/db

Have I done something wrong?

Now I have done the

sudo mkdir -p /data/db

Sun Oct 30 19:35:19 [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

Sun Oct 30 19:35:19 dbexit: 

Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close listening sockets...

Sun Oct 30 19:35:19 [initandlisten] shutdown: going to flush diaglog...

Sun Oct 30 19:35:19 [initandlisten] shutdown: going to close sockets...

Sun Oct 30 19:35:19 [initandlisten] shutdown: waiting for fs preallocator...

Sun Oct 30 19:35:19 [initandlisten] shutdown: lock for final commit...

Sun Oct 30 19:35:19 [initandlisten] shutdown: final commit...

Sun Oct 30 19:35:19 [initandlisten] shutdown: closing all files...

Sun Oct 30 19:35:19 [initandlisten] closeAllFiles() finished

Sun Oct 30 19:35:19 [initandlisten] shutdown: removing fs lock...

Sun Oct 30 19:35:19 [initandlisten] couldn"t remove fs lock errno:9 Bad file descriptor

Sun Oct 30 19:35:19 dbexit: really exiting now

EDIT Getting error message for

sudo chown mongod:mongod /data/db

chown: mongod: Invalid argument


You created the directory in the wrong place

/data/db means that it's directly under the '/' root directory, whereas you created 'data/db' (without the leading /) probably just inside another directory, such as the '/root' homedirectory.

You need to create this directory as root

Either you need to use sudo

e.g : sudo mkdir -p /data/db

Or you need to do su - to become superuser, and then create the directory with mkdir -p /data/db


MongoDB also has an option where you can create the data directory in another location, but that's generally not a good idea, because it just slightly complicates things such as DB recovery, because you always have to specify the db-path manually. I wouldn't recommend doing that.


the error message you're getting is "Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied". The directory you created doesn't seem to have the correct permissions and ownership -- it needs to be writable by the user who runs the MongoDB process.

To see the permissions and ownership of the '/data/db/' directory, do this: (this is what the permissions and ownership should look like)

$ ls -ld /data/db/

drwxr-xr-x 4 mongod mongod 4096 Oct 26 10:31 /data/db/

The left side 'drwxr-xr-x' shows the permissions for the User, Group, and Others. 'mongod mongod' shows who owns the directory, and which group that directory belongs to. Both are called 'mongod' in this case.

If your '/data/db' directory doesn't have the permissions and ownership above, do this:

sudo chmod 0755 /data/db

sudo chown mongod:mongod /data/db

that should make it work..

Check here to better understand the meaning of the directory permissions:

Maybe also check out one of the tutorials you can find via Google: "UNIX for beginners"

Answer is