mongo-将一个字段更新到另一个字段中
场景
有文档
{
"id":1,
"registerTime":"2023-01-09 12:32:10"
"tags":[
{
"name":"tom",
"createTime":"2023-01-09 12:32:10"
}
]
}
将 registerTime
字段数据更新到 tag.createTime
db.getCollection('t_user').updateOne(
{
"id":2},
[
{"$set": {"tag.createTime": "$registerTime"}}
]
)
//或
db.getCollection('t_user').updateMany(
{},
[
{"$set": {"tag.createTime": "$registerTime"}}
]
)