Skip to content

Instantly share code, notes, and snippets.

@karan9
Created August 27, 2020 13:23
Show Gist options
  • Save karan9/4bbfdb292dfd343a382f979eaaaf340c to your computer and use it in GitHub Desktop.
Save karan9/4bbfdb292dfd343a382f979eaaaf340c to your computer and use it in GitHub Desktop.
A simple mongo shell script to return the connections grouped by the source
db.currentOp(true).inprog.reduce(
(accumulator, connection) => {
ipaddress = connection.client ? connection.client.split(":")[0] : "Internal";
accumulator[ipaddress] = (accumulator[ipaddress] || 0) + 1;
accumulator["TOTAL_CONNECTION_COUNT"]++;
return accumulator;
},
{ TOTAL_CONNECTION_COUNT: 0 }
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment