Moogose填充如何将sud文档填充到另一个集合中

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

组织者,产品集合,我需要加入带有已发布用户ID和组织者集合的产品表,并再次与用户和组织者一起购买用户ID。我可以与用户加入产品,但不能与组织者加入用户。

Products.find({})
  .populate({
    path: 'intresteduserIds.userId',
    // Get friends of friends - populate the 'friends' array for every friend
    populate: { path: 'intresteduserIds.user_organizationid' } /* How to join with organizer collection which have organizer id*/
  })
 .populate('product_postedby');
node.js mongodb mongoose mongoose-populate
1个回答
0
投票

您需要在内部填充中设置model属性。

因此,请在代码中导入Organizer模型,并像这样使用它:(请注意,管理器周围没有任何字符串。)

Products.find({})
  .populate({
    path: 'intresteduserIds.userId',
    populate: { path: 'intresteduserIds.user_organizationid', model: Organizer } 
  })
 .populate('product_postedby');
© www.soinside.com 2019 - 2024. All rights reserved.