Skip to content

Instantly share code, notes, and snippets.

@samarthbhargav
Created July 24, 2014 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samarthbhargav/0d0c27832f7592588570 to your computer and use it in GitHub Desktop.
Save samarthbhargav/0d0c27832f7592588570 to your computer and use it in GitHub Desktop.
A Shell Script to Import Multiple Collections from a Folder
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"
echo "Enter Path to mongo_dump:"
read mongodump
for file in "$mongodump"/*
do
echo "Found file: $file"
echo "Command: mongoimport --db $dbname --collection `basename $file` --host $host --authenticationDatabase $authdb --username $username --password $password --file $file"
mongoimport --db $dbname --collection `basename $file` --host $host --authenticationDatabase $authdb --username $username --password $password --file $file
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment