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

159
Visualizações
How to replace a string in all records using Robo 3T?

I'm using MongoDB and Robo 3T. In some documents I have a field parent with the value "0" (string). I want to replace it with "NA". In order to get all records I did:

db.getCollection('mycollection').find({}).forEach(function(doc) {
        var json = JSON.stringify( doc );
        if ( json.match(/"parent":"0"/) != null ) {
            printjson(doc);
        }
    });

Now, how can I replace the "parent":"0" with "parent":"NA" in all records?

EDIT: Another attempt:

db.getCollection('mycollection').find({}).forEach(function(doc) {
     var json = JSON.stringify( doc );
    if ( json.match(/"parent":"0"/) != null ) {
            var obj = JSON.parse(json, (key, value) => {

              return (key === 'parent' && value === '0')
                ? value.replace('0', 'NA')
                : value;
            });
        }
        //doc = obj;
        printjson(obj);
    });

Which works. But updating the record by doing doc = obj doesn't work. How to fix it?

over 4 years ago · Santiago Trujillo
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