Append a string to the end of an existing field in MongoDB

后端 未结 6 1287
灰色年华
灰色年华 2020-12-02 23:22

I have a document with a field containing a very long string. I need to concatenate another string to the end of the string already contained in the field.

The way I

6条回答
  •  既然无缘
    2020-12-03 00:11

    For example (it's append to the start, the same story ):

    before

    { "_id" : ObjectId("56993251e843bb7e0447829d"), "name" : "London City", "city" : "London" }

    db.airports
       .find( { $text: { $search: "City" } })
       .forEach(
           function(e, i){ 
               e.name='Big ' + e.name; 
               db.airports.save(e);
           }
        )
    

    after:

    { "_id" : ObjectId("56993251e843bb7e0447829d"), "name" : "Big London City", "city" : "London" }

提交回复
热议问题