import { Meteor } from 'meteor/meteor';

import { Posts } from '../';

Meteor.publish('posts', () => Posts.find({}, { limit: 10 }));

import { Meteor } from 'meteor/meteor';

import { Posts, Comments } from '../';

Meteor.publishComposite('posts', (limit = 10) => {
  return {
    find() {
      return Posts.find({}, {
        limit,
        sort: {
          createdAt: -1,
        },
      });
    },
    children: [
      {
        find(post) {
          return Comments.find({
            postId: post._id,
          }, {
            sort: {
              createdAt: -1,
            },
            limit: 3,
          });
        },
      },
    ],
  };
});

Join comments on posts publication
Join comments on posts publication
