I have a nearly 100k records with same policies with different kind 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"
}