MongoDB concatenate strings from two fields into a third field

前端 未结 8 1463
逝去的感伤
逝去的感伤 2020-12-09 09:14

How do I concatenate values from two string fields and put it into a third one?

I\'ve tried this:

db.collection.update(
  { \"_id\": { $exists: true          


        
8条回答
  •  长情又很酷
    2020-12-09 10:17

    You can use aggregation operators $project and $concat:

    db.collection.aggregate([
      { $project: { newfield: { $concat: [ "$field1", " - ", "$field2" ] } } }
    ])
    

提交回复
热议问题