익명 05:05

How I will check that the mongodb service is runing or not using terminal comman...

How I will check that the mongodb service is runing or not using terminal command?

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.

Command 1. pgrep mongod this command will return me PID (process Id).

Command 2. 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

Command 3. 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

link:- https://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac

Command 4. 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?

link:- https://www.rosehosting.com/blog/how-to-list-all-services-in-linux/

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.



Top Answer/Comment:

You could run something along the lines of

if pgrep -x mongodd
 then echo "ok"
 else echo "not ok"
fi
상단 광고의 [X] 버튼을 누르면 내용이 보입니다