1 回答

TA貢獻(xiàn)2051條經(jīng)驗(yàn) 獲得超10個(gè)贊
您可以嘗試使用$map,
viewed
您的邏輯和代碼對(duì)于and保持不變visitorIps
$mergeObjects將合并當(dāng)前游標(biāo)字段和
viewed
我們visitorIps
計(jì)算的
await User.updateMany({},
[{
$set: {
posts: {
$map: {
input: "$posts",
as: "post",
in: {
$mergeObjects: [
"$$post",
{
"viewed": {
$add: [{ $size: "$$post.visitorIps" }, "$$post.viewed"]
},
"visitorIps": []
}
]
}
}
}
}
}]
)
添加回答
舉報(bào)