The error message you are getting is “Unable to create lock file: /data/db/mongod.lock errno: 13 Permission denied. The directory you are creating does not seem to have the correct permission and ownership. This required to be writeable by the users who run on the MongoDB process.
Check the permission and ownership:
To see the permission and ownership of the ‘/data/db/’ directory, that is what the permission 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 permission for users, groups, and others. Mongod mongod shows who owns the directory and which group that the directory belongs to.
If your ‘/data/db/’ directory does not have the permission and ownership above, then do this;
First, check what user and group your mongo user has;
# grep mongo /etc/passwd
you must have an entry for mongod in /etc/passwd, as it is a daemon.
sudo chmod 0755 /data/db
sudo chown -R 498:496 /data/db # using the user-id , group-id
The user can also use the user-name and group-name as follows;
sudo chown -R mongod:mongod /data/db
That should make it work.
In the comments below, some people use this;
sudo chown -R $USER /data/db
sudo chmod -R go+w /data/db
The disadvantage is that the $USER is an account that has a login shell. Daemons ideally have not the shell for the security reasons, that’s why you see in the grep of the password file.