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
Get the number of open connections in MongoDB?
To get the number of open connections in MongoDB, use the serverStatus() method which returns comprehensive server statistics including connection information.
Syntax
db.serverStatus()
Example
Execute the following command to retrieve server status ?
db.serverStatus()
This will produce output with various server metrics. Look for the connections section ?
{
"host" : "DESKTOP-QN2RB3H",
"version" : "4.0.5",
"process" : "mongod",
"connections" : {
"current" : 1,
"available" : 999999,
"totalCreated" : 1
},
// ... other server statistics
}
Key Points
- current: Number of currently active/open connections
- available: Number of additional connections the server can accept
- totalCreated: Total number of connections created since server start
Get Only Connection Information
To retrieve only connection-related statistics, use ?
db.serverStatus().connections
{
"current" : 1,
"available" : 999999,
"totalCreated" : 1
}
Conclusion
Use db.serverStatus().connections.current to get the number of open connections. The serverStatus() method provides comprehensive server metrics including active connections, available connection slots, and total connections created.
Advertisements
