I ran into the same problem, and I solved it, and here are the step-by-step instructions:
Before trying everything else, just go to the mongodb directory, which contains the bin directory for mongodb, and just use the command in the terminal:
sudo bin / mongod
running mongodb as root, and you may be asked to enter a password as root. If you still cannot run mongodb, then do the following:
First, let's see the mongodb data directory resolution mode by typing in Terminal:
ls -ld / data strong>
(ps or we can simply type "ls -l /" to see permission modes for all directories and files in the root directory, including the / data directory.)
And the permission mode for the root user must be "rwx", namely, the root user can read, write and execute files. To make this happen, we use the command to change the resolution mode by typing in the terminal:
chmod 755 / data strong>
(that is, 755 is a separate octal entry of the permission setting argument) This sets the permission modes / data directory to "rwxr-xr-x", namely, the root user can read, write and execute, while the group user and everyone else can read and execute.
Note: if you are denied this operation, enter instead:
sudo chmod 755 / data strong>
to set permission as root user.
Then, when this step is completed, return the permission modes by typing again: ls -ld / data strong>
and the output should look like this:
drwxr-xr-x 3 root wheel 102 March 3 17:00 / data
(ps you donโt need to worry about โdโ at the beginning) and note that the setup of โrwxr-xr-xโ is now done.
Then we are all set up, and now you can return to the mongodb directory and enter:
sudo bin / mongod
to run mongodb.
Hope this helps.