4

I have a field

"data" : {
        "user" : "derp",
        "id" : "xHOSTNAME_xderp"

I want to replace all docs with xHOSTNAME_* to yHOSTNAME_. Any idea how to search and replace. I've seen some other posts similarly related but none seemed to work.

1

1 Answer 1

8
db.test1.find().forEach(function(doc) {
    doc.data.id = doc.data.id.replace('xHOSTNAME_', 'yHOSTNAME_');
    db.test1.save(doc);
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.