Imagine you have multiple collections you want displayed on a single social news feed, for example Posts
and Users
(new signups). How would you rea
By far the easiest solution is to merge them on the client in a template helper. For example:
Template.dashboard.helpers({
peopleAndPosts: function() {
var people = People.find().fetch();
var posts = Posts.find().fetch();
var docs = people.concat(posts);
return _.sortBy(docs, function(doc) {return doc.createdAt;});
}
});
and the template (assuming people and posts have a name
):
{{#each peopleAndPosts}}
- {{name}}
{{/each}}
This will be reactive because the helper is a reactive context so any changes to People
or Posts
will cause the returned array to be recomputed. Be aware that because you are not returning a cursor, any changes to either collection will cause the entire set to render again. This won't be a big deal if the length of the returned array is relatively short.