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

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

6 days ago

How to Setup MEAN App with LangChain.js

Hey there! As I venture into building agentic MEAN apps with LangChain.js, I wanted to…

2 weeks ago

Build AI Chatbots for SAAS Using LLMs, RAG, Multi-Agent Frameworks

Software-as-a-Service (SaaS) providers have long relied on traditional chatbot solutions like AWS Lex and Google…

2 weeks ago

Creating a RAG Application Using LangGraph: Example Code

Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…

3 weeks ago

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

3 weeks ago

Building an OpenAI Chatbot with LangChain

Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…

3 weeks ago