批量更改mongo grid filename

根据规则修改mongo grid filename

一:按行和,号切分生成名字mapping文件
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


二:执行shell脚本将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"


遗留问题:
在rails中通过gem:mongo上传的文件到grif,但是没有找到方法循环更改filename。
http://api.mongodb.com/ruby/current/Mongo/Grid/FSBucket.html

猜你喜欢

转载自schooltop.iteye.com/blog/2338282