Cursor on publish

Hi, just a quick question.

i have an example of publication using aggregation.

Meteor.publish('tags', function(tag){
 	var sub = this;
	var pipeline = [
		{$project: {tags:1, author: 1, title:1, permalink:1 }},
		{$unwind:"$tags"},
		{$match: {"tags": tag}}];
	var results = Posts.aggregate(pipeline);
	var arrayLength = results.length;
	for(var i=0; i < arrayLength; i++){
		  var tags = results[i];
          sub.added('posts', Math.random(), tags);
	}
	sub.ready();
});

why do i need to have an additional loop to store a data in the collection posts.

for(var i=0; i < arrayLength; i++){
    		  var tags = results[i];
              sub.added('posts', Math.random(), tags);
    	}
    	sub.ready();

Do you mean that piece of code? If so then you should know that you do not store any data, you just say for DDP than document with id = Math.random() with fields = tags was added into posts collection. And it should be transfered to all subscribers (client apps)

1 Like

thanks @mrzafod . i think this answer my question :smile: