I created /data/db
in root directory and ran ./mongod
:
[initandlisten] exception in initAndListen: 20 Attempted to create a lock fi
I dealt with the same problem:
Change to the MongoDB directory which contains the bin
directory, and run:
sudo bin/mongod
Running MongoDB as the root user you might be asked to enter the root password. If you still can not run the MongoDB, then check the permissions for MongoDB's data directory. Enter:
ls -ld /data
or type ls -l /
for the permissions for all directories and files in the directory including the /data
directory.
The permission mode for the root user should be "rwx
", meaning the root user is able to read, write and execute the files.
To make this happen, we use:
chmod 755 /data
755
is a octal notation to set the permissions, of the /data
directory to "rwxr-xr-x
", which means the root user can read, write and execute, whereas the "group" and "everyone"are able to only read and execute.
Note: When you can't do this, type instead:
sudo chmod 755 /data
to set the permission as the root user.
Then, when done with that step, recapture the permission modes using:
ls -ld /data
which should look like:
drwxr-xr-x 3 root wheel 102 Mar 3 17:00 /data
You don't need to worry about the "d
" at the beginning, and notice that the permissions reflect "rwxr-xr-x
".
You can now change back to the MongoDB directory and type:
sudo bin/mongod
to run MongoDB.