MongoDB Status Check Commands
The following represents some of the commands that can be used to check the status of MongoDB database. Note that mongod represents the daemon process of MongDB databass and, primarily, used to manage database access. Following are some of the commands which can be used to get the status of Mongodb:
- service mongod status: Displays the status of MongodB service as like the screenshot given below.
- systemctl status mongod: Displays the same status of MongoDB service as like above command as shown in figure 1.
- pgrep mongo: Prints the process ID of running mongo instance. pgrep command looks through the list of running processes and list down the process ids based on name.
- ps -e | grep mongo: Prints the process detail of running mongo instance
- nc -v localhost 27017: Prints whether connection to mongodb running on port 27017 is succeeded.
- mongostat: This command provides a real-time view of the database’s performance and status. It shows information such as connections, operations, memory usage, and more.
- mongotop: This command displays real-time data about the amount of time each MongoDB operation takes to complete, as well as the collection and index involved in each operation.
- db.stats(): This command is used within the MongoDB shell to retrieve statistics about the current database, including data size, index size, storage size, and the number of objects and indexes.
- db.serverStatus(): This command provides a detailed overview of the MongoDB server’s current status, including information about connections, memory usage, network activity, replication, and more.
Monitoring the status of your MongoDB database is vital for ensuring its optimal performance. By utilizing commands like ‘service mongod status,’ ‘systemctl status mongod,’ ‘pgrep mongo,’ ‘ps -e | grep mongo,’ ‘mongo,’ ‘mongostat,’ ‘mongotop,’ ‘db.stats(),’ and ‘db.serverStatus(),’ you can effectively check the status, gain insights, and monitor various aspects of your MongoDB deployment. By incorporating these commands into your monitoring routine, you can proactively identify issues, maintain reliability, and optimize the performance of your MongoDB database.