notes icon indicating copy to clipboard operation
notes copied to clipboard

MongoDB copy field value to another field

Open lanlin opened this issue 7 years ago • 0 comments

情景

某些时候我们需要将某个字段的值拷贝给同一张表下面的其他字段。

代码

db.my_collection.aggregate(
    [
        { "$addFields": { 
            "name": { "$concat": [ "$firstName", " ", "$lastName" ] } 
        }},
        { "$out": "my_collection" }
    ]
);

lanlin avatar May 14 '18 07:05 lanlin