Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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.
Advertisements
