Skip to content

Instantly share code, notes, and snippets.

@EyalAr EyalAr/dbcopy.sh
Last active Aug 29, 2015

Embed
What would you like to do?
Export from one mongo database into another
#!/usr/bin/env bash
#https://gist.github.com/EyalAr/4bc6524c3c9ae6af33a9
SOURCE_HOST=127.0.0.1
SOURCE_DB=dev
TARGET_HOST=127.0.0.1
TARGET_DB=stage
COLLECTIONS="col1 col2 col3"
for c in ${COLLECTIONS[@]}
do
echo "$SOURCE_HOST/$SOURCE_DB/$c --> $TARGET_HOST/$TARGET_DB/$c"
mongoexport --host $SOURCE_HOST -d $SOURCE_DB -c $c | mongoimport --host $TARGET_HOST -d $TARGET_DB -c $c
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.