javascriptmongodbmeteorsimple-schemameteor-collection2

Populate subdocument in Meteor


I have a schema which has a subdocument defined by another schema like so:

Child schema

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

Parent schema

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

Now, when I read a Parent type object, I get a child object's id in its child property.

Is there a way I can populate the child property of parent, so that I can get the whole Child object as a subdocument, instead of just a string of id (much like populating subdocuments in mongoose)?


Solution

  • Found this helpful, although a little longer than simply calling populate()