Batch change mongo grid filename

Modify mongo grid filename according to the rules

1: Generate name mapping files by line and number segmentation
File.open("/Users/jamst/ebuychem/script/config_u.conf",'w') do |f|
  EbuychemAttachment.where("attachment_type != 'ProblemOrderMessage'").each do |ec|
	pp = "uploads/#{ec.attachment_type.to_s.underscore}/path/#{WhUtils.split_id(ec.attachment_id,false)}/#{ec.path},uploads/#{ec.attachment_type.to_s.underscore}/path/#{WhUtils.split_id(ec.id,false)}/#{ec.path}"
	f.write("#{pp}\n")
  end
end


Two: Execute the shell script to change the name of the mongo file
#! /bin/sh

while read mongoData ; do

            data1=`echo $mongoData | grep -v '#' | awk -F ',' '{print $1}'`

            data2=`echo $mongoData | grep -v '#' | awk -F ',' '{print $2}'`

            mongoDataChang="db.fs.files.update({filename:"\"$data1\""},{"\$set":{filename:"\"$data2\""}},false,true)"

            a=$mongoDataChang

            echo $a

            mongo test --eval "$a"

done < "/root/config_u.conf"


Remaining problem:
Uploaded files via gem:mongo in rails to grif, but no way found to change filename cyclically.
http://api.mongodb.com/ruby/current/Mongo/Grid/FSBucket.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326509125&siteId=291194637