如何在nodejs中映射两个csv文件

时间:2018-08-16 10:23:52

标签: javascript node.js lodash

recdb
  .getCollection(SRCCOL)
  .find()
  .forEach(row => {
  //By default, put it as MISSING, if there is a MATCH, it will either show up as MATCHED/MISMATCHED
  reccol.insert(copyRow(row, {
    recStatus: ‘MISSING’,
    primaryKey: row[recCfg.primaryKey.recSrcFile]
  }));
});

recdb
  .getCollection(TSTCOL)
  .find()
  .forEach(tstRow => {
  var srcRow = recdb.getCollection(RESCOL).findOne(_.set({}, recCfg.primaryKey.recSrcFile, tstRow[recCfg.primaryKey.recTestFile]));
  if (srcRow) {
    if (srcRow.recStatus === ‘MATCHED’ || srcRow.recStatus === ‘MISMATCH’) {
      //Check for duplicates and mark them
      reccol.insert(copyRow(tstRow, {
        recStatus: ‘DUPLICATE’,
        primaryKey: tstRow[recCfg.primaryKey.recTestFile]
      }));
    } else {

      recCfg.mappings.forEach(mpg => {
        if (_.trim(srcRow[mpg.src]) != _.trim(tstRow[mpg.tst])) {
          if (!mpg.diffExpected) srcRow.recStatus = ‘MISMATCH’;
          srcRow[mpg.src] = {
            srcValue: srcRow[mpg.src],
            tstValue: tstRow[mpg.tst]
          };
        }
      });
      reccol.update(srcRow);
    }
  } else {
    //Record not found, so new record
    reccol.insert(copyRow(tstRow, {
      recStatus: ‘ADDED’,
      primaryKey: tstRow[recCfg.primaryKey.recTestFile]
    }));
  }
});

console.log(‘Generating output...’);

在比较两个CSV文件(SRC和TST)(例如美国和美国)(US | United States)时,我的结果csv文件应为“ MATCHTCH”到“ MATCHED”

检查此图像,它包含SRC,TST和RESULT表: Check this image, it contains SRC , TST and RESULT tables.

0 个答案:

没有答案