I\'m writing an app using mongo as its db. I want to print the clients connected to the db, for example, print their ip. How can I get that info?
I tried using
You should be able to run this command and get a list of connected IP addresses:
db.currentOp(true).inprog.forEach(function(d){if (d.client)printjson(d.client)})
db.currentOp is actually built on top of the special collection $cmd.sys.inprog so you can also query that directly. You can get an idea of the how to do that by typing in db.currentOp without the parentheses into the mongo shell and it will print out the source for the function:
> db.currentOp
function ( arg ){
var q = {}
if ( arg ) {
if ( typeof( arg ) == "object" )
Object.extend( q , arg );
else if ( arg )
q["$all"] = true;
}
return this.$cmd.sys.inprog.findOne( q );
}