1 回答
TA贡献2051条经验 获得超10个赞
您可以尝试使用$map,
viewed
您的逻辑和代码对于and保持不变visitorIps
$mergeObjects将合并当前游标字段和
viewed
我们visitorIps
计算的
await User.updateMany({},
[{
$set: {
posts: {
$map: {
input: "$posts",
as: "post",
in: {
$mergeObjects: [
"$$post",
{
"viewed": {
$add: [{ $size: "$$post.visitorIps" }, "$$post.viewed"]
},
"visitorIps": []
}
]
}
}
}
}
}]
)
添加回答
举报