How to check if MongoDB is running (status commands)
Codemia Knowledge Hub ·
On Linux with systemd, run sudo systemctl status mongod. On Windows, run sc query MongoDB. A running service is half the answer, so then confirm the server accepts connections.
Service status on Linux
On systemd systems such as Ubuntu or CentOS, check the status:
The output shows whether MongoDB is active (running) or inactive (stopped), plus the process ID and recent log lines. Start it if needed:
Service status on Windows
MongoDB runs as a Windows service. Check its status:
The output includes a state such as RUNNING or STOPPED. Start it with:
Confirming it accepts connections
Open the shell:
If the server is up, you get a prompt connected to the default test database. On MongoDB 6.0 and later the legacy mongo shell is no longer shipped; use mongosh instead.
From Python with pymongo:
If it is not running or you can't connect
- Configuration: check that
mongod.confhas the right IP bindings and port. - Logs: read
/var/log/mongodb/mongod.logon Linux, or the log in the installation directory on Windows. - Ports and firewall: make sure the MongoDB port (default
27017) is open through any firewall. - Resources: make sure there is enough CPU and memory for the MongoDB processes.
| Step | Description | Commands/Tools |
| 1 | Check MongoDB service status | systemctl status mongod
sc query MongoDB |
| 2 | Start MongoDB service if not running | systemctl start mongod
net start MongoDB |
| 3 | Test MongoDB connection | mongo shell
pymongo script |
| 4 | Review logs for issues | tail /var/log/mongodb/mongod.log |
| 5 | Verify network settings and ports | Check firewalls and port bindings |
Keep the configuration secure at the network and data level so the server is not open to unauthorized access.
Related reading
- Is MongoDB v2.6's WriteConcern Broken?
- Is Morton code the most efficient for higher dimensions?
- Is multi-AZ RDS really worth it?
- Is one source to many target cluster replication supported by YugabyteDB’s 2-DC async replication mechanism?
- Is Session.runfetches guaranteed to execute its fetches arguments in-order?
- Is the --group option deprecated from kafka-console-consumer tool? if so, how can I set the consumer group using kafka-console-consumer.
- Is Oracle OpenAsync etc... not a truly async method?
- Is pgbench supported for YugaByte DB?
System design interview problems on this topic
- Design a Distributed OLTP Database: solution and walkthrough
- Design a Wide Column Database: solution and walkthrough
- Design a Key Value Store: solution and walkthrough
- Design a Web Cache: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.