You would want to create a mongo script prints the ids, then have a bash script that loops through it and creates a link for each id.
Here's some code for it.
Setup - create Mongodb Dummy collection
db = connect("test");
db.dummy.insert({ _id : "345kjh34k5" });
db.dummy.insert({ _id : "8945ng49" });
db.dummy.insert({ _id : "3459t8u34" });
Setup - Create sample file
Filename: file1.txt
File1 content. Blah blah blah.
MongoDB script print dummy ids
Filename: printDummyIds.js
db = connect("test");
var linkNames = db.dummy.find().map(function(doc){
print( doc._id );
});
Output:
mongo --quiet printDummyIds.js
345kjh34k5
8945ng49
3459t8u34
Bash script that calls mongo then creates soft links
Filename: createLinksFromIds.sh
echo Linking files to source.
echo Source: $1
ext="${1#*.}"
out="./out/"
mkdir $out
for id in $(mongo --quiet printDummyIds.js)
do
lName=$out$id"."$ext ;
echo Creating $lName ;
ln -s $1 $lName ;
done
Usage
createLinksFromIds.sh FILE_PATH
FILE_PATH is the file that you want to link.
Example:
bash createLinksFromIds.sh file1.txt
Output:
Linking files to source.
Source: file1.txt
Creating ./out/345kjh34k5.txt
Creating ./out/8945ng49.txt
Creating ./out/3459t8u34.txt