Reputation: 55
I'm trying to retrieve data from meteor collection. While being successfully able to insert data, the data is not getting fetched. I'm using iron router. Page appears blank without any error or warning message in the browser console.
list-article.js
Template.articleList.helpers({
articles: function () {
return Articles.find();
}
// articles: [
// { "articleTitle": "title1" },
// { "articleTitle": "title2" }
// ]
});
list-article.html
<template name="articleList">
{{#each articles}}
<li>{{articleTitle}}</li>
{{/each}}
</template>
Connecting meteor mongodb using terminal, data already exist:
Command: db.articles.find();
{ "_id" : "Ctck6hkfx3NkoTAe4", "articleTitle" : "sdfsdf" }
{ "_id" : "JyNCggxtsFeQ9y9bi", "articleTitle" : "sdfsdfsdf" }
{ "_id" : "dGvjdzu4FeQRaEx7a", "articleTitle" : "gfhfgh" }
{ "_id" : "T9Lr3WswRhhLhNPsu", "articleTitle" : "sdfsdf", "articleAbstract" : "yfdhfgh" }
{ "_id" : "dNAZAFutb24qA6JP9", "articleTitle" : "fghf", "articleAbstract" : "sdf", "articleDescription" : "df", "articleReference" : "dfgd", "articleNote" : "dfgrtr", "createdAt" : ISODate("2015-03-24T17:18:04.731Z") }
Upvotes: 0
Views: 350
Reputation: 7139
Without autopublish
, your data isn't automatically sent over the wire despite the server and the client having the Collection. You have to publish some data from the collection on the server, and subscribe to this publication on the client. Thus,
//server code
Meteor.publish('allArticles', function() {
return Articles.find();
});
And:
//client code
Meteor.subscribe('allArticles');
And you've got your data on the client. More about Publications and Subscriptions on the doc.
Upvotes: 1