Once a Mongo Daemon is started, it starts listening to the client connections on a port. Any client can connect to the MongoDB Database if they are connected in the network and have access to the database.

In this tutorial, we shall learn to find the number of MongoDB Connections made to a MongoDB Server using db.serverStatus() method.

db.serverStatus() provides lot of information about the MongoDB Server. We can get the information explicitly about the number of connections made to the server by running the command db.serverStatus().connections from any of the MongoDB Shell connected to the Server.

Following is a quick snapshot the command run from a MongoDB Shell.

Number of Connections to MongoDB Server

From the above picture, you can observe that there are three “current” connections to the MongoDB Server. These connections can be either active or inactive. Also, the number of “available” slots for new connections is 999997. So, in total, a MongoDB Server can support a million connections.

Now we shall start a Mongo Shell that connects to the MongoDB Server and observe the values.

Number of Connections to MongoDB Server - from Mongo Shell

With this new MongoDB Shell making a connection to the MongoDB Server, the number of connections has been incremented by one and the number of open connections available is reduced by 1.

ADVERTISEMENT

Conclusion

In this MongoDB Tutorial, we have learned to find the number of connections made a MongoDB Server.