Skip to content

Instantly share code, notes, and snippets.

@scien
Created February 1, 2013 04:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scien/4689274 to your computer and use it in GitHub Desktop.
Save scien/4689274 to your computer and use it in GitHub Desktop.
.mongorc.js example
prompt = function() {
var ndocs, obj, p, sec;
ndocs = function(n) {
return "" + n + " document" + (n > 1 ? 's' : '');
};
db.setProfilingLevel(2);
obj = db.getLastErrorObj();
p = db.system.profile.find({
$and: [
{ns: {$not: /profile$/}},
{ns: {$not: /\$cmd$/}},
{ns: {$not: /indexes$/}}
]
}).sort({ts: -1}).limit(1)[0];
sec = "" + (p.millis / 1000) + " sec";
if (obj.err) {
return "Error: " + obj.err + "\n> ";
}
switch (p.op) {
case 'insert':
return "Query OK, 1 document inserted (" + sec + ")\n> ";
case 'query':
return ">= " + (ndocs(p.nreturned)) + " in set (" + sec + ")\n> ";
case 'remove':
return "Query OK, x documents removed (" + sec + ")\n> ";
case 'update':
return "Query OK, " + (ndocs(p.nupdated)) + " affected (" + sec + ")\n> ";
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment