Querying connection information in MongoDB
As with all other database platforms, daily administration and troubleshooting of MongoDB often begins with analyzing database activity. It can be helpful to see all connections from within MongoDB, which you can do by running:
where the “true” makes the command include idle connections. But often there's so many connections that unless you capture the output in a script file or some similar thing, it's kind of useless.
Thanks to a hint given by Scott Hernandez in the mongodb-user forum, we can use the line
to show a subset that is more manageable. For instance, we might want to show all connections from a particular application server:
or from the MongoDB logs we’ll see a particular connectionId and want to know where it came from:
This will then show all the connection info for that connectionId: