Skip to content

Instantly share code, notes, and snippets.

@nroe
Forked from matteofigus/mongo-ls.js
Last active December 28, 2017 04:43
Show Gist options
  • Select an option

  • Save nroe/b9d1b07e83b096b5566e52fbe46d9830 to your computer and use it in GitHub Desktop.

Select an option

Save nroe/b9d1b07e83b096b5566e52fbe46d9830 to your computer and use it in GitHub Desktop.
A script to list all the collections and document count for a specific mongodb db
// Usage: mongo {Server without mongodb:// example 127.0.0.1:27017}/{DbName} [-u {Username}] [-p {Password}] < ./mongo-ls.js
var collections = db.getCollectionNames();
for (var i = 0; i < collections.length; i++) {
var name = collections[i];
if (name.substr(0, 6) != 'system')
print(name + ' - ' + db[name].count() + ' records(' + parseInt(db[name].storageSize()/1024/1024*100)/100 + ' MB)' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment