How can I replace a character in mongodb with another character in a collection? -
i have collection contains documents having delimiter "|".
{
"_id" : objectid("57bbe4342a00d122b0075fbb"),
"phone_search" : "9255958588|9138115601|9034223813",
"address" : "central complex market|rohtak road|sonipat|rohtak road-131001|sonepat|haryana",
"national_catidlineage_search" : "/10255012/|/10406930/",
"area" : "rohtak road",
}
is there command in mongodb can replace "|"s ","s documents in collection?
this question answered here how replace string in documents in mongo
// change 'collection' name yours in db.collection.find , db.collection.update: var cursor = db.collection.find(); while (cursor.hasnext()) { var x = cursor.next(); print("before: "+x['phone_search']); x['phone_search'] = x['phone_search'].replace('|', ','); print("after: "+x['phone_search']); // uncomment next line persist: // db.collection.update({_id : x._id}, x); }
Comments
Post a Comment