Skip to content

Instantly share code, notes, and snippets.

@mping
Last active July 19, 2016 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mping/a9fa6a187f1857dd8a54dd2e6729a460 to your computer and use it in GitHub Desktop.
Save mping/a9fa6a187f1857dd8a54dd2e6729a460 to your computer and use it in GitHub Desktop.
mongodb common ops
// drop all non-system colls
db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) db[c].drop(); })
// clear old profiles
db.setProfilingLevel(0); db.system.profile.drop(); db.setProfilingLevel(1, 100)
// view top profile queries
db.getCollection('system.profile').find({}, {ns: 1, query:1, millis:1, command: 1}).sort({millis:-1})
//slow queries starting from a given date
db.getCollection('system.profile').find({ts: { $gte : new ISODate("2016-07-15T13:00:00.000Z") }})
// index stats
db.collection.stats().indexSizes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment