Skip to content

Instantly share code, notes, and snippets.

@s-petit
Last active September 23, 2019 12:17
Show Gist options
  • Select an option

  • Save s-petit/2c87d096a085a1c42995a6295d0f0329 to your computer and use it in GitHub Desktop.

Select an option

Save s-petit/2c87d096a085a1c42995a6295d0f0329 to your computer and use it in GitHub Desktop.
Mongo commands
### 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