Quick Solution
Run the following in your Terminal:
ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
This will get you the number of MongoDB processes running, thus if it is other than 0, then you have MongoDB running on your system.
Step-by-Step
-
The
ps -ef | grep mongodpart return all the running processes, that have any relation to the supplied string, i.e.mongod, e.g. have the string in the executable path, have the string in the username, etc. -
When you run the previous command, the
grep mongodalso becomes a process containing the stringmongodin theCOMMANDcolumn ofpsoutput, so it will also appear in the output. For that reason you need to eliminate it by pipinggrep -v grep, which filters all the lines from the input that contain the stringgrep. -
So now you have all possible lines that contain string
mongodand are not the instances ofgrep. What to do? Count them, and do that withwc -l. -
wc -loutput contains additional formatting, i.e. spaces, so just for the sake of the beauty, runtr -d ' 'to remove the redundant spaces.
As a result you will get a single number, representing the number of processes you grep‘ed for.