2

I have a Mongo database collection, with _id and value as the two keys. What I'm trying to accomplish is to search all the documents in my collection for occurrences of a specific string and replace that with a new string.

{
    "_id" : "12345678",
    "value" : "Lorem ipsum"
}

Also, extending it further, can I accomplish the same when I have a nested document structure?

{
    "_id" : "12345678",
    "someKey" : {
        "value1" : "Lorem ipsum",
        "value2" : "Lorem ipsum"
        }
}
Halley
  • 521
  • 10
  • 35

1 Answers1

-1
db.application.find({},{ "ref_no": 1 }).forEach(function(doc) {
doc.ref_no = doc.ref_no.trim();
db.application.update(
   { "_id": doc._id },
   { "$set": { "ref_no": doc.ref_no } }
);
})
Farid Blaster
  • 974
  • 1
  • 9
  • 23