Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

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

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"
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda