猫鼬-如何更新多个文档异步

时间:2019-03-20 22:36:11

标签: mongodb mongoose

我正在尝试通过如下查询一次更新/创建多个文档:

Follower.updateAsync(
   { organization: event.organization, user: { $each: userIds.map(userId => userId) } },
   { organization: event.organization, user: { $each: userIds.map(userId => userId) } },
   { new: true, upsert: true, setDefaultsOnInsert: true, multi: true },
);

但是,在此示例中,userObjectId,根据Mongo文档,使用$each仅适用于数组。我可以做些什么来基本上遍历一组id并让它一次在这里创建/更新所有内容?

我知道如果我做这样的事情,条目将被创建/更新,但是我需要能够对一系列的userIds做到这一点:

Follower.updateAsync(
   { organization: event.organization, user: userIds[0]._id },
   { organization: event.organization, user: userIds[0]._id },
   { new: true, upsert: true, setDefaultsOnInsert: true, multi: true },
);

0 个答案:

没有答案
相关问题