我在stages
文档中有一个MentorProfile
数组,我想用lessonsWithComments
连接stages
数组。这是否可能,而不必循环通过lessonsWithComments
,然后使用updateMany
查询每次迭代
MentorProfile.updateMany(
{},
{
$push: {
stages: {
lessonsWithComments
}
}
}
).then((update) => res.json(update));
我希望这可以帮助你。
MentorProfile.updateMany(
{},
{ $push: { stages: { $each: lessonsWithComments } } }
).then((update) => res.json(update));
见:https://docs.mongodb.com/manual/reference/operator/update/push/