#!bin/bash
MONGO_SRV="mongodb://10.6.36.60" #线上mongo集群连接地址
SRV_RANGE=(1 1)                  #区服范围 闭区间 [m,n]
DB=()
function fixSrv {
  mongo $MONGO_SRV 2>&1 >/dev/null <<-EOF
   db = db.getSiblingDB('$1')
   db.getCollection("role_daily_timer").find().forEach(function (item){
     item.daily_timer.forEach(
       function(d,index){
         db.getCollection("daily_timer").insertOne({
           "_id":item._id+":"+d.type,
           "type":NumberInt(d.type),
           "last_handle_time":d.last_handle_time,
           "role_id":item._id,
         })
       }
     )
   })
  EOF
  echo 修复完成:$1
}

for srvId in $(seq ${SRV_RANGE[0]} ${SRV_RANGE[1]}); do
  DB[${#DB[*]}]="db_vikingar_master_$srvId"
done

for db in ${DB[*]}; do
  fixSrv $db &
done
wait
echo "done..."