Skip to content

Instantly share code, notes, and snippets.

@SPodjasek
Last active August 21, 2023 12:41
Show Gist options
  • Save SPodjasek/0efada6ffabace847a3f095f312a9683 to your computer and use it in GitHub Desktop.
Save SPodjasek/0efada6ffabace847a3f095f312a9683 to your computer and use it in GitHub Desktop.
MonoDB useful queries

Show connection count...

  • by appName:
    db.currentOp(true).inprog.reduce((acc,conn) => { 
      var appName = conn.appName ?? ''; acc[appName] = (acc[appName] ?? 0) + 1; return acc;
    }, {});
    
  • by client ip
    db.currentOp(true).inprog.reduce((acc,conn) => { 
      var ip = conn.client ? conn.client.split(':')[0] : 'internal'; acc[ip] = (acc[ip] ?? 0) + 1; return acc;
    }, {});
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment