// mongorestore --port 62701 -u coloring  -p coloring123. --authenticationDatabase=admin --db coloring_ol total_done_rates.bson  --drop

const models = require('../models')



// 初始化art表的areaCountFloor字段， 以及total_done_rate 统计相关的几个字段
async function mergeStatics() {
  console.time('mergeStatics');

  let docs = await models.Art.find();
  console.log(`total: ${docs.length}`);

  for (let doc of docs) {
    console.log(`process art: ${doc._id}`);
    let totalDoneRateDoc = await models.TotalDoneRate.findById(doc._id);
    if (totalDoneRateDoc) {
      doc.totalStartCount = totalDoneRateDoc.totalStartCount;
      doc.totalDoneCount = totalDoneRateDoc.totalDoneCount;
      doc.completionRate = totalDoneRateDoc.completionRate;
    }

    await doc.save();
  }

  console.timeEnd('mergeStatics');
}


mergeStatics()
  .then(console.log)
  .catch(console.error)
  .finally(() => require('process').exit());