Skip to content

Instantly share code, notes, and snippets.

@marcoberri
Last active December 17, 2015 13:13
Show Gist options
  • Select an option

  • Save marcoberri/4c28b94ab9890adb6dcc to your computer and use it in GitHub Desktop.

Select an option

Save marcoberri/4c28b94ab9890adb6dcc to your computer and use it in GitHub Desktop.
MongoDB - Get last profiled query in all db
var dbs_list = db.getMongo().getDBNames();
for(var d in dbs_list){
var name = dbs_list[d];
if(name == 'admin' || name == 'local')
continue;
dbOne = db.getSisterDB(name);
print("dbname -->" + name);
var cursor = dbOne.system.profile.find( { op:"query", millis : { $gte : 5 },ns : { $ne : (name + '.system.profile') } },{ ts:1,millis:1, nscanned:1, nreturned:1, ns:1, query:1} ).sort({ts:-1}).limit(5);
cursor.forEach(function(r) {
print(JSON.stringify(r));
});
print();
print();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment