Last active
December 15, 2015 16:09
-
-
Save piercemoore/5286741 to your computer and use it in GitHub Desktop.
MongoDB Shell Scripts to make your doggone life easier
This file contains 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
/** | |
* 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