Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!