NoSQL

MongoDB – Commands to Check the Status of MongoDB Database

This article represents different commands which can be used to check the status of MongoDB database on Linux/Ubuntu. Please feel free to comment/suggest if I missed to mention one or more important points. Also, sorry for the typos.

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. It is recommended to check the log file (/var/log/mongo/mongo.log) to get details.
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. This command holds good for MongoDB version >= 2.6. Ensure that you are logged in as root. Else use “sudo” command as prefix.

    Fig 1. MongoDB Status Check

    If you are having MongoDB version < 2.6, the following command will be applicable:

    service mongodb status

  • 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 -edaf | grep mongo: Prints the process detail of running mongo instance
  • ps -ax | grep mongo: Returns number of mongod instances that are running
  • nc -zvv 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.

Conclusion

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.

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

View Comments

Share
Published by
Ajitesh Kumar
Tags: mongodbnosql

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

1 month ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

1 month ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

1 month ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

1 month ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

2 months ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

2 months ago