Mongodb query to find the match and update the column with the value in JavaScript

I have a nearly 1lakh records with same policies with different king of in line … Read more Mongodb query to find the match and update the column with the value in JavaScript

I have a nearly 1lakh records with same policies with different king of in line data. I just want to update the column with the records are matched or not with the "Y" value

var bulk = db.getCollection("Sample").initializeUnorderedBulkOp();
db.getCollection("Sample")
  .find()
  .forEach(function (doc) {
    var theQuery = {
      "_id.policy": doc.policy,
    };
    var theUpdate = {
      $set: {
        "$[t].Match": Y,
      },
    };
    var arrayFilter = [
      {
        "t.policy": doc.policy,
        "t.object": doc.object,
        "t.code": doc.code,
        "t.interest": doc.interest,
        "t.line": doc.line,
        "t.code": doc.code,
      },
    ];
    bulk.find(theQuery).arrayFilters(arrayFilter).update(theUpdate);
  });

My Data looks like below :

 "_id" : {
        "policy" : "243",
        "object" : "SB",
        "code" : "Collision",
        "interest" : "OT",
        "line" : "786",
        "codeBX" : "7892"
    },
    "Match" : "y"
}
{
    "_id" : {
        "policy" : "234",
        "object" : "TB",
        "code" : "Collision1",
        "interest" : "TT",
        "line" : "938",
        "codeBX" : "7948"
    },
    "Match" : "y"
}
{
    "_id" : {
        "policy" : "6243",
        "object" : "US6",
        "code" : "PD",
        "interest" : "MO",
        "line" : "536",
        "codeBX" : "011"
    },
    "Match" : "y"
}
{
     "_id" : {
        "policy" : "6243",
        "object" : "US6",
        "code" : "PD",
        "interest" : "MO",
        "line" : "536",
        "codeBX" : "011"
    },
    "Match" : "y"
}

Source: JavaSript – Stack Overflow


Categories: NewsTags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *