I am trying to switch my app from autopublish to publish/subsribe. After trying to set publish/subscribe up or my first collection, none of my items from the collection are being displayed anymore, and I am at a loss at what might be going wrong.
Can someone spot a mistake in my code below or give any hints as to how to debug this type of problem?
Codejak, you need to expose your collection data to the template, so that the template knows what data to display.
// Use the name of your template here
Template.mycollectionlist.helpers({
// the name of the data that will be available
myCollection: function () {
// You can do filtering in the find function
return MyCollection.find();
}
});
You should have this in the same folder place as your template, using the same name, but as a .js file.
I would recommend going through the meteor tutorial, it covers most of these basic concepts, and I wold classify this as a very basic concept, at least when using the Blaze render enginge, which is the default.
Doing it in React for example would be somewhat different.
I have worked through the tutorial and referred back to it multiple times. I guess what it doesn’t achieve in conveying is what parts of different approaches/patterns are (absolutely) required, which aspects are equivalent between approaches and which ones are (optional) additions. Which probably isn’t the point of a tutorial in the first place.
I guess I now have to take this to understand that I always need a helper to expose data to a template (wording in the tutorial: “You can pass data into templates from your JavaScript code by defining helpers.”)
This blog details the multiple ways of defining the data context. A very good read, though outdated on a few points. Example being Iron:Router has been largely replaced/overtaken by kadira:flow-router, where data in the router is not a good idea.
And the book this site promotes is also a fantastic introduction to meteor beyond the very basics. Well worth the investment.
If you want to specifically -debug- your subscriptions, I would definitely use https://atmospherejs.com/msavin/mongol, which allows you to see all the data available in the client. If your data is not in there, your publish/subscribe is not working.
and in level UP (channel in youtube) in the intermediate meteor tutorials describe the funcion of meteorToys. (and is a exellent channel to learn of meteor).