Syntax error Check the current number of connections to MongoDB?

Check the current number of connections to MongoDB?



You can check the current number of connections to MongoDB with the help of the following syntax −

var anyVariableName= db.serverStatus();
yourVariableName.connections;

The second syntax is as follows −

db.serverStatus().connections;

To understand both the above syntaxes, let us see them one by one −

Case 1 − The first query is as follows −

> var checkCurrentNumberOfConnections = db.serverStatus()
> checkCurrentNumberOfConnections.connections;

The following is the output −

{ "current" : 1, "available" : 999999, "totalCreated" : 1 }

Case 2 − The second query is as follows −

> db.serverStatus().connections

The following is the output −

{ "current" : 1, "available" : 999999, "totalCreated" : 1 }
Updated on: 2019-07-30T22:30:25+05:30

821 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements