Skip to content

Instantly share code, notes, and snippets.

@kbychkov
Last active April 13, 2019 01:57
Show Gist options
  • Save kbychkov/403741ad239afbcbdc291225c33de22e to your computer and use it in GitHub Desktop.
Save kbychkov/403741ad239afbcbdc291225c33de22e to your computer and use it in GitHub Desktop.

MongoDB Cheatsheet

Query plan

db.collection.find().explain()
db.collection.find().explain({ verbose: 'executionStats' })

Profiling

db.getProfilingStatus()
db.getProfilingLevel()
db.setProfilingLevel(1, { slowms: 20 })

db.system.profile.find().limit(10).sort( { ts : -1 } ).pretty()
db.system.profile.find( { millis : { $gt : 5 } } ).pretty()

Indexes

db.collection.getIndexes()
db.collection.createIndex({ field: 1 })
db.collection.createIndex({ field: 'hashed' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment