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

157
Vistas
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?

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