Created
February 11, 2021 13:03
-
-
Save philpoore/856dcfb483ace80e28326d1bbd0812d8 to your computer and use it in GitHub Desktop.
MongoDB handy scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////// | |
// Get currently running ops, good for finding out indexing progress | |
db.currentOp().inprog.map(a => a.msg) | |
/* [ | |
undefined, | |
undefined, | |
"Index Build: scanning collection Index Build: scanning collection: 10385246/54469342 19%", | |
] */ | |
////////////////////////////// | |
// Get index names for given collection | |
db.collection.getIndexes().map(a => a.name) | |
////////////////////////////// | |
// Collection stats | |
const p = (a, s, lr = false) => ('' + a).pad(s, lr) | |
let collectionStats = () => { | |
print( | |
p('collection', 30, true), | |
p('count', 12), | |
p('size', 12), | |
p('storageSize', 12), | |
p('indexSize', 12), | |
p('numIndexes', 12) | |
) | |
print('-'.repeat(95)) | |
db.getCollectionNames().forEach((collection) => { | |
const stats = db[collection].stats(1024**3) | |
print( | |
p(collection, 30, true), | |
p(stats.count, 12), | |
p(stats.size, 12), | |
p(stats.storageSize, 12), | |
p(stats.totalIndexSize, 12), | |
p(stats.nindexes, 12) | |
) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment