2016-08-24 3 views
-1

구분 기호가 "|"인 문서가 포함 된 모음이 있습니다.mongodb의 문자를 컬렉션의 다른 문자로 바꾸려면 어떻게해야합니까?

{

"_id": ObjectId가 ("57bbe4342a00d122b0075fbb"),

"phone_search": "9255958588 | 9138115601 | 9034223813",

"주소": "중앙 복잡한 시장 | Rohtak 도로 | Sonipat | Rohtak 도로 131001 | Sonepat | 하리 아나 "

"national_catidlineage_search ":"/ 10255012/|/10406930/",

"영역": |들의 컬렉션의 모든 문서는 ""와 "" "Rohtak 도로",

}

모두를 대체 할 수 MongoDB의 어떤 명령이 있습니까?

+0

항상 질문을 게시하기 전에 먼저 검색 대답했다. 처음 두 개의 Google 검색 결과에서 이미 비슷한 두 개의 게시물이 있습니다. [this] (http://stackoverflow.com/questions/10042450/how-to-replace-string-in-all-documents-in-mongo) 및 [this] (http://stackoverflow.com/questions/)를 참조하십시오. 12589792/how-to-replace-substring-in-mongodb-document) ... –

답변

0

이 질문은 여기 How to replace string in all documents in Mongo

// Change 'collection' name for yours in db.collection.find and 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 to persist: 
    // db.collection.update({_id : x._id}, x); 
} 
관련 문제