Check the current number of connections to MongoDB?

To check the current number of connections to MongoDB, you can use the db.serverStatus().connections command. This returns detailed connection statistics including current, available, and total connections created.

Syntax

db.serverStatus().connections;

Alternative syntax using a variable ?

var connectionInfo = db.serverStatus();
connectionInfo.connections;

Method 1: Direct Command

The simplest way to check connection statistics ?

db.serverStatus().connections;
{ "current" : 1, "available" : 999999, "totalCreated" : 1 }

Method 2: Using a Variable

Store the server status and access connection data ?

var checkCurrentNumberOfConnections = db.serverStatus();
checkCurrentNumberOfConnections.connections;
{ "current" : 1, "available" : 999999, "totalCreated" : 1 }

Understanding the Output

The connections object contains three key fields ?

  • current - Number of active connections to the MongoDB instance
  • available - Number of additional connections the server can accept
  • totalCreated - Total number of connections created since server startup

Conclusion

Use db.serverStatus().connections to monitor MongoDB connection statistics. Both direct command and variable methods provide identical results, with the variable approach useful when accessing multiple server status fields.

Updated on: 2026-03-15T00:11:49+05:30

896 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements