MongoDB concatenate strings from two fields into a third field

前端 未结 8 1467
逝去的感伤
逝去的感伤 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:00

    You can also follow the below.

    db.collectionName.find({}).forEach(function(row) { 
        row.newField = row.field1 + "-" + row.field2
        db.collectionName.save(row);
    });
    

提交回复
热议问题