Skip to content

Instantly share code, notes, and snippets.

@elhoyos
Last active May 25, 2016 21:34
Show Gist options
  • Save elhoyos/6e6b0d18810e2edc0b05 to your computer and use it in GitHub Desktop.
Save elhoyos/6e6b0d18810e2edc0b05 to your computer and use it in GitHub Desktop.
mongo: Copy a collection
$ mongodump -d some_database -c some_collection
$ mongorestore -d some_other_db -c some_or_other_collection dump/some_collection.bson
$ mongodump --version
mongodump version: r3.2.6
git version: 6dab8f99eaafb764443531dc528d4b4b76eb57f2
$ mongodump -h {HOST} -d {DATABASE} -u {USER} -p {PASSWORD} -c {COLLECTION} -o - | mongorestore -h {HOST} -d {DATABASE} -u {USER} -p {PASSWORD} -c {COLLECTION} --dir -
# To s3
$ mongodump -h {HOST} -d {DATABASE} -u {USER} -p {PASSWORD} -c {COLLECTION} -o - | gzip -c | aws s3 cp - s3://{BUCKET}/{FILENAME}.gz
$ mongoexport -h host -u user -p password -d db -c collection | mongoimport -h target_host -d db -c collection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment