{"id":5649,"date":"2014-04-04T15:17:23","date_gmt":"2014-04-04T15:17:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/client-subscribe-not-receiving-data-from-meteor-server-publish-collection-of-common-programming-errors\/"},"modified":"2014-04-04T15:17:23","modified_gmt":"2014-04-04T15:17:23","slug":"client-subscribe-not-receiving-data-from-meteor-server-publish-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/04\/client-subscribe-not-receiving-data-from-meteor-server-publish-collection-of-common-programming-errors\/","title":{"rendered":"Client subscribe not receiving data from Meteor server publish-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;ve been banging my head against the wall for a while now, and I assume I&#8217;m missing something simple here.<\/p>\n<p>I&#8217;m running this on my Meteor server:<\/p>\n<pre><code>\/\/ --- Collections ---\nProjects = new Meteor.Collection('projects');\nTeam = new Meteor.Collection('team');\n\n\/\/ --- Only publish user data for users on my team ---\nMeteor.publish('team', function() {\n    var team = Meteor.users.findOne({_id: this.userId}).profile._team;\n    console.log(Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}}).fetch());\n    return Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}});\n});\n<\/code><\/pre>\n<p>This finds all of the users who are on the same &#8220;team&#8221; by running a query on all user documents who have the same id in the <code>profile._team<\/code> property as the currently logged in user. You&#8217;ll see the <code>console.log(...);<\/code> in the publish function (on the line before the return statement), and it correctly logs the documents I expect it to in my terminal.<\/p>\n<p>Now I&#8217;m running this on my client:<\/p>\n<pre><code>\/\/ --- Data ---\nMeteor.subscribe('team');\nTeam = new Meteor.Collection('team');\n\nTemplate.team.team = function() {\n    console.log(Team.findOne());\n    return Team.find();\n};\n<\/code><\/pre>\n<p>However, the <code>console.log(Team.findOne())<\/code> always logs undefined, <code>Team.find()<\/code> always returns an empty array. What am I doing incorrectly that is stopping my documents from reaching the client?<\/p>\n<p><strong>UPDATE:<\/strong> Here&#8217;s the template code.<\/p>\n<pre><code>\n    {{&gt; team}}\n\n\n\n    <br \/>TEAM TEMPLATE WORKS<br \/><br \/>\n    {{#each team}}\n        <br \/>TEAM EACH WORKS<br \/><br \/>\n        \n            {{profile.firstName}} {{profile.lastName}}\n        \n    {{\/each}}\n\n<\/code><\/pre>\n<p>&#8220;TEAM EACH WORKS&#8221; is never rendered inside the <code>{{#each}}<\/code> tag, but &#8220;TEAM TEMPLATE WORKS&#8221; renders as expected when it is placed before the <code>{{#each}}<\/code> tag.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been banging my head against the wall for a while now, and I assume I&#8217;m missing something simple here. I&#8217;m running this on my Meteor server: \/\/ &#8212; Collections &#8212; Projects = new Meteor.Collection(&#8216;projects&#8217;); Team = new Meteor.Collection(&#8216;team&#8217;); \/\/ &#8212; Only publish user data for users on my team &#8212; Meteor.publish(&#8216;team&#8217;, function() { var [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5649","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5649"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5649\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}