Skip to content

Instantly share code, notes, and snippets.

@samarthbhargav
Created July 24, 2014 09:16
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samarthbhargav/afa42c835487338edff5 to your computer and use it in GitHub Desktop.
Save samarthbhargav/afa42c835487338edff5 to your computer and use it in GitHub Desktop.
A Shell Script to Export multiple collections
echo "Enter HostName:"
read host
echo "Enter DB Name:"
read dbname
echo "Enter Auth DB Name: (usually admin)"
read authdb
echo "Enter Username:"
read username
echo "Enter Password"
read password
echo "Credentials: Host: $host, DB:$dbname, AuthDB:$authdb, Username:$username, Password:$password"
while true; do
echo "Enter Collection to export: "
read collection
echo "Exporting Collection: $collection"
echo "Command: mongoexport --db $dbname --collection $collection --host $host --authenticationDatabase $authdb --username $username --password $password --out $collection"
mongoexport --db $dbname --collection $collection --host $host --authenticationDatabase $authdb --username $username --password $password --out $collection.json
echo "Export Done, Check $collection.json"
echo "Export Another Collection? [y/n] :"
read response
if [ "$response" != "y" ]
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment