Last active
September 23, 2019 12:17
-
-
Save s-petit/2c87d096a085a1c42995a6295d0f0329 to your computer and use it in GitHub Desktop.
Mongo commands
This file contains hidden or 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
| ### Dump a Mongo database | |
| mongodump --host <HOST> --port <PORT> -d <DATABASE> -u <USER> -p <MDP> --gzip | |
| ### Restore a Mongo database | |
| mongorestore -d <DATABASE> -u <USER> -p <MDP> --host <HOST> --dir <DUMP_LOCATION> --gzip | |
| ### drop all collections | |
| delete_collection_list = ["a", "b", "c"]; | |
| delete_collection_list.forEach( function (collection) { | |
| if (db.getCollectionNames().indexOf(collection)>=0) { | |
| db.getCollection(collection).drop(); | |
| print("Deleted Collection: "+ collection); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment