Using publishComposite how to access to the data of the children collection, I should subscribe me to the children in the client site?


#1

I have the following publishComposite:

if (Meteor.isServer) {
    Meteor.publishComposite('groupsAndMessages', function(groupID){
        return {
            find: function () {
                return Groups.find({ _id: groupID });
            },
            children: [
                {
                    find: function (group) {
                        return Messages.find(
                            { _id: { $in: group.messages }}
                        )
                    },
                    children: [
                        {
                            find: function(message,group) {
                                return Meteor.users.find(
                                    { _id: message.created_by },
                                    );
                            }
                        }
                    ]
                },
                {
                    find: function(group) {
                        return Meteor.users.find(
                            { _id: { $in: group.users }}
                        )
                    }
                }
            ]
        }
    });
};

And in the client site I have:

this.subscribe('groupsAndMessages');

        this.helpers({
            currentGroup() {
                return Groups.find({ _id: this.groupId })
            }
        });

My question is how I can to return messages of a specific group? I don’t know if I should subscribe again to Publish Messages, because when I do this
console.log(Messages.find({}));
or
console.log(Messages.findOne({_id : messageId}));
they don’t return anything. Thanks for your time