1

Being new to javascript and surly baby in Meteor. I could not make sense reading this part of the docs. about Meteor.publish(name, func)

Arguments
name String
Name of the record set. If null, the set has no name, and the record set is automatically sent to all connected clients.

I take it that record set means Meteor Collection, if that is correct, then how can a publish action take place on a collection with name "null" or even a collection with no name as stated? I mean, where is the collection to publish if the first parameter "that collection name" is null or does not exist? Thanks

Fred J.
  • 5,759
  • 10
  • 57
  • 106
  • "record set means Meteor Collection"? Not quite. There's a wonderful answer to a related question, which clarifies relations between record sets, meteor collections, mongo collections, etc: http://stackoverflow.com/a/21853298/1429390 . After reading that answer, the documentation you cite seemed much clearer. – Stéphane Gourichon Mar 17 '17 at 16:32

2 Answers2

1

The name parameter in Meteor.publish has absolutely nothing to do with the collection. While the convention is that you should have similar naming to what collection(s) you're using, you could literally call a publish function "asdjfsaidfj" and it would be valid. As yudap said, what data you're sending to the client is entirely determined in the function. You can also return data from multiple collections using an array:

return [
    ExampleCollection.find(),
    AnotherCollection.find()
];
Stephen Woods
  • 4,049
  • 1
  • 16
  • 27
0

If you publish data with null argument:

Meteor.publish(null, func)

Basically it is the same as you autopublish without autopublish package. That's mean you don't need to subscribe and you don't need to install autopublish package. The data is ready in client and reactive and you can use it in whatever template without subscribing.

where is the collection to publish? Whatever collection you want to autopublish. Just define it in func:

Meteor.publish(null, function () {
  CollectionName.find({}, {
    /*
    sort: Sort specifier,
    skip: Number,
    limit: Number,
    fields: Field specifier,
    reactive: Boolean,
    transform: Function
    */
  });
});
asingh
  • 524
  • 3
  • 10