Skip to content

Instantly share code, notes, and snippets.

@serpent403
Last active January 2, 2016 00:49
Show Gist options
  • Save serpent403/8225967 to your computer and use it in GitHub Desktop.
Save serpent403/8225967 to your computer and use it in GitHub Desktop.
Imports all bson files present in a directory into the given database. Name of bson file must match the corresponding collection name. Place this script in the directory where your bson files are present and run it.
#!/bin/bash
host=localhost
db=mydatabase
for bson_file in `ls *.bson`
do
echo "importing $bson_file"
collection=$(echo "${bson_file}" | cut -d'.' -f1)
bson_path="$(pwd)/$bson_file"
mongoimport --host $host --db $db --collection $collection $bson_path
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment