Skip to content

Instantly share code, notes, and snippets.

@jamesholcomb
Created September 19, 2022 14:49
Show Gist options
  • Save jamesholcomb/54ee58e673717e14e2f9226f21a9fc73 to your computer and use it in GitHub Desktop.
Save jamesholcomb/54ee58e673717e14e2f9226f21a9fc73 to your computer and use it in GitHub Desktop.
Clones a mongodb collection and its indexes into __collection__
#!/bin/bash
if [[ -z "$1" || -z "$2" ]]
then echo -e "Usage: clone-collection.sh <db> <collection>"; exit 1
fi
# clones a mongodb collection and its indexes into __collection__
mongodump -v -d $1 -c $2 --out=- | mongorestore -v -d $1 -c __$2__ --drop --dir=-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment