Skip to content

Instantly share code, notes, and snippets.

@minmax
Created November 9, 2014 16:17
Show Gist options
  • Save minmax/0a8564015f25745f1f44 to your computer and use it in GitHub Desktop.
Save minmax/0a8564015f25745f1f44 to your computer and use it in GitHub Desktop.
Print mongo collections names and objects count
var dbs_names = db.adminCommand('listDatabases');
for (var i = 0; i < dbs_names.databases.length; i += 1) {
var current_db = connect(dbs_names.databases[i].name);
var collection_names = current_db.getCollectionNames();
for (var j = 0; j < collection_names.length; j += 1) {
var collection = current_db[collection_names[j]];
var size = collection.stats().count;
print(dbs_names.databases[i].name + '\t' + collection_names[j] + ':\t' + size);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment