I'm using mongodb database to save my application data into collection but by some reasons the mongodb connection is break and there is lot of problems occurs and I want to check the mongodb connection through terminal command. I searched for it and I found three commands which will be used but I'm confused that which command I have to use in the golang code.
pgrep mongod this command will return me PID (process Id).
ps -ef | grep mongod this command will returns me
mongodb 15678 1 1 13:58 ? 00:00:01 /usr/bin/mongod --config /etc/mongod.conf
ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' ' this command I found from the stackoverflow accepted answer and it may be returns 0, 1. if there is other value except 0 then your mongodb is running as the answer say you can see link of the question
service --status-all | grep mongod will show me the mongod service with a signed like
[ + ], or [ - ]. In the documentation they says that if the service with
[ + ] the service is running and
[ - ] the service is stopped. But on my localhost the mongod is running and it will show me
[ - ] mongod when I execute this command. Why?
Please tell me that which Command I have to used to check that the mongodb is running or not I have to use that command in my golang code.