在 Meteor 中填充子文档

Populate subdocument in Meteor

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

子架构

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(很像 mongoose 中的 populating 子文档)?

发现 有帮助,尽管比简单地调用 populate()

要长一点