[SOLVED] Nested subscriptions

Hi,

I have a collection named Features where the field “source” is an id from another collection “Sources”.
I know that I can use template level subscription but is there a way to publish the corresponding source each time I want to publish the feature?

something like this for instance doen’t work:

Meteor.publish('features_byId', function(id){
	var feature = Features.find({ _id:id});
	var source = Sources.find({ _id:feature.source});
	return [feature,source];
});

thanks for your help

Look at publish-composite

Looks great, thanks!

This must work :wink:

Meteor.publish('features_byId', function(id){
  var feature = Features.find({_id:id});
  var sourceIds = _.pluck(feature.fetch(), 'source');
  var source = Sources.find({_id: {$in: sourceIds}});
  
  return [feature,source];
});

This works as well, and without additional package :slightly_smiling: