Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda