连接数组与文档中的现有数组[重复]

问题描述 投票:0回答:1

我在stages文档中有一个MentorProfile数组,我想用lessonsWithComments连接stages数组。这是否可能,而不必循环通过lessonsWithComments,然后使用updateMany查询每次迭代

MentorProfile.updateMany(
                {},
                {
                    $push: {
                        stages: {
                            lessonsWithComments
                        }
                    }
                }
            ).then((update) => res.json(update));
mongodb
1个回答
1
投票

我希望这可以帮助你。

MentorProfile.updateMany(
   {},
   { $push: { stages: { $each: lessonsWithComments } } }
).then((update) => res.json(update));

见:https://docs.mongodb.com/manual/reference/operator/update/push/

© www.soinside.com 2019 - 2024. All rights reserved.