Skip to content

Instantly share code, notes, and snippets.

@EyalAr
Last active August 29, 2015 14:02
Show Gist options
  • Save EyalAr/4bc6524c3c9ae6af33a9 to your computer and use it in GitHub Desktop.
Save EyalAr/4bc6524c3c9ae6af33a9 to your computer and use it in GitHub Desktop.
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