Skip to content

Instantly share code, notes, and snippets.

@piercemoore
Last active December 15, 2015 16:09
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 piercemoore/5286741 to your computer and use it in GitHub Desktop.
Save piercemoore/5286741 to your computer and use it in GitHub Desktop.
MongoDB Shell Scripts to make your doggone life easier
/**
* Links and such
*
* http://docs.mongodb.org/manual/reference/mongo-shell/
* http://docs.mongodb.org/manual/reference/javascript/
* http://docs.mongodb.org/manual/reference/meta-query-operators/
*/
/**
* Show the names of all collections and the number of documents in each of them.
*/
var colls = db.getCollectionNames();
colls.forEach(function(x) {
print( x + " - " + db[x].count() );
})
/**
* Loop through all collections and drop all records
*/
var colls = db.getCollectionNames();
colls.forEach(function(x) {
db[x].drop();
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment