How to get connected clients in MongoDB?

To get connected clients in MongoDB, use the db.currentOp() method with true parameter to display all operations including idle connections. The client field in the output shows the IP address and port of each connected client.

Syntax

db.currentOp(true)

Example

Run the following command to view all connected clients ?

db.currentOp(true)

The output displays all connected clients with detailed information ?

{
   "inprog" : [
      {
         "host" : "DESKTOP-QN2RB3H:27017",
         "desc" : "conn1",
         "connectionId" : 1,
         "client" : "127.0.0.1:61787",
         "appName" : "MongoDB Shell",
         "clientMetadata" : {
            "application" : {
               "name" : "MongoDB Shell"
            },
            "driver" : {
               "name" : "MongoDB Internal Client",
               "version" : "4.0.5"
            },
            "os" : {
               "type" : "Windows",
               "name" : "Microsoft Windows 10",
               "architecture" : "x86_64",
               "version" : "10.0 (build 17134)"
            }
         },
         "active" : true,
         "currentOpTime" : "2019-03-30T05:13:34.296+0530",
         "opid" : 12538,
         "lsid" : {
            "id" : UUID("da370b0f-093a-45f3-b1fe-697daca8ccd2"),
            "uid" : BinData(0,"47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=")
         },
         "secs_running" : NumberLong(0),
         "microsecs_running" : NumberLong(160815),
         "op" : "command",
         "ns" : "admin.$cmd.aggregate"
      },
      {
         "host" : "DESKTOP-QN2RB3H:27017",
         "desc" : "LogicalSessionCacheRefresh",
         "active" : false,
         "currentOpTime" : "2019-03-30T05:13:34.296+0530"
      }
   ],
   "ok" : 1
}

Key Information

The important fields for identifying connected clients are ?

  • client : Shows the IP address and port (e.g., "127.0.0.1:61787")
  • desc : Connection description (e.g., "conn1" for client connections)
  • appName : Application name connecting to MongoDB
  • active : Whether the connection is currently active
  • connectionId : Unique identifier for the connection

Conclusion

Use db.currentOp(true) to monitor all connected clients in MongoDB. The client field reveals the source IP and port, while other fields provide connection details and activity status.

Updated on: 2026-03-15T00:39:42+05:30

903 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements