Created
August 9, 2017 21:59
-
-
Save cornelisonc/fcca3d80503c9c28904e0937f39dafc0 to your computer and use it in GitHub Desktop.
Bash Script to Download Files from GridFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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