2016-08-24 1 views
-1

デリミタ「|」を持つドキュメントを含むコレクションがあります。mongodbの文字をコレクション内の別の文字と置き換えるにはどうしたらいいですか?

{

"_id":ObjectIdが( "57bbe4342a00d122b0075fbb")、

"phone_search": "9255958588 | 9138115601 | 9034223813"、

"アドレス":「中央複雑な市場| Rohtakロード|ソーニーパト| Rohtak ロード-131001 | Sonepat |ハリヤナ」、

"national_catidlineage_search": "/ 10255012/|/10406930 /"、

"エリア": "Rohtakの道"、

}

すべてを置き換えることができますMongoDBの中に任意のコマンドがあります "|" sの "" Sコレクション内のすべての文書のため?

+0

答えました。私は最初の2つのGoogleの結果で見つけた既に2つの同様の投稿があります。 [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); 
} 
関連する問題