Skip to content

Instantly share code, notes, and snippets.

@shantanuo
Forked from matteofigus/mongo-ls.js
Created April 24, 2019 05:23
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 shantanuo/2610f10551cec307e8fc6c4b1693a09c to your computer and use it in GitHub Desktop.
Save shantanuo/2610f10551cec307e8fc6c4b1693a09c 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();
print('Collections inside the db:');
for(var i = 0; i < collections.length; i++){
var name = collections[i];
if(name.substr(0, 6) != 'system')
print(name + ' - ' + db[name].count() + ' records');
}
@shantanuo
Copy link
Author

list all collections and document count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment