Last active
October 4, 2019 02:46
-
-
Save mrfrase3/5d0218b0ac5229ce7daf25a6507e1446 to your computer and use it in GitHub Desktop.
Transfer Mongo Database Between Servers
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
#!/bin/bash | |
# Author: mrfrase3 | |
# run: | |
# chmod +x ./transfer.sh | |
# ./transfer.sh <oldURI> <newURI> <oldDBName> <newDBName> | |
# e.g. | |
# ./transfer.sh "mongodb://olduser:[email protected]/old-db" "mongodb://newuser:[email protected]/new-db" "old-db" "new-db" | |
mongodump --uri="$1" --gzip --archive="transfer.gz" | |
mongorestore --nsFrom "$3.*" --nsTo "$4.*" --uri "$2" --drop --gzip --archive="transfer.gz" | |
rm transfer.gz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I keep getting annoyed having to refer to the docs every time I want to do this