【问题标题】:Populate subdocument in Meteor在 Meteor 中填充子文档
【发布时间】:2017-03-14 12:26:04
【问题描述】:

我有一个架构,它的子文档由另一个架构定义,如下所示:

子架构

export const Child = new Mongo.Collection('Child');
Child.schema = new SimpleSchema({ ... });
Child.attachSchema(Child.schema);

父架构

export const Parent = new Mongo.Collection('Parent');
Parent.schema = new SimpleSchema({
    child: { type: Child },
    ...
});
Parent.attachSchema(Parent.schema);

现在,当我读取一个Parent 类型的对象时,我在其child 属性中获得了一个子对象的ID。

有没有一种方法可以填充父级的child 属性,这样我就可以将整个Child 对象作为子文档获取,而不仅仅是一串id(很像populating mongoose 中的子文档)?

【问题讨论】:

    标签: javascript mongodb meteor simple-schema meteor-collection2


    【解决方案1】:

    发现this 很有帮助,虽然比简单地调用populate() 有点长

    【讨论】:

      猜你喜欢
      • 2018-08-16
      • 2014-08-16
      • 2021-10-07
      • 2017-01-27
      • 1970-01-01
      • 2020-12-18
      • 2015-08-08
      • 2017-04-06
      • 2017-05-07
      相关资源
      最近更新 更多