Skip to content

Instantly share code, notes, and snippets.

@cornelisonc
Created August 9, 2017 21:59
Show Gist options
  • Save cornelisonc/fcca3d80503c9c28904e0937f39dafc0 to your computer and use it in GitHub Desktop.
Save cornelisonc/fcca3d80503c9c28904e0937f39dafc0 to your computer and use it in GitHub Desktop.
Bash Script to Download Files from GridFS
#!/bin/bash
while read -r line; do
file=$(echo "$line" | awk -F'\t' '{ print $1 }')
[[ $file == 'connecting to'* ]] && continue
file_id="$(cut -d'|' -f1 <<<"$file")"
file_key="$(cut -d'|' -f2 <<<"$file")"
mkdir $file_id && cd "$_"
mongofiles -d meteor --prefix="cfs_gridfs.filesStore" get_id 'ObjectId("'$file_key'")'
cd ../
done < <(mongo meteor --eval 'db.cfs.files.filerecord.find().forEach(function(o) {if (o.copies) {print(o._id + "|" + o.copies.filesStore.key);}})')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment