Why am I not getting any Document fields from my Collection to display?


#1

In my Meteor app, I’ve got this HTML/Spacebars to display all the Documents from a MongoDB Collection:

<template name="peopleGrid">
  <h2>People to Ping</h2>
  <table cols="10" id="peopleTbl" name="peopleTbl">
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <COLGROUP width="10%"></COLGROUP>
      <TR>
          <TD class="headerrow" align="center" valign="middle">
               <strong>First</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
              <strong>Last</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle" colspan="4">
                <strong>Address 1</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>Address 2</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>City</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>State</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>Zip</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>Email</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>Phone</strong>
          </TD>
          <TD class="headerrow" align="center" valign="middle">
                <strong>Notes</strong>
          </TD>
       </TR>
       {{#each person}}
         <tr>
           <td>{{per_firstname}}</td>
           <td>{{per_lastname}}</td>
           <td>{{per_streetaddr1}}</td>
           <td>{{per_streetaddr2}}</td>
           <td>{{per_placename}}</td>
           <td>{{per_stateorprov}}</td>
           <td>{{per_zipcode}}</td>
           <td>{{per_emailaddr}}</td>
           <td>{{per_phone}}</td>
           <td>{{per_notes}}</td>
         </tr>
       {{/each}}
  </table>
</template>

It is putting the “headers” row of the table on the page, but none of the data; there are two Documents in the collection. The method to get the fields (“person”) is in the corresponding .js file:

Template.main.helpers({
    person: function() {
      return People.find({}, {
        sort: {
          per_lastname: 1
        },
        fields: {
          per_firstname: 1,
          per_lastname: 1,
          per_streetaddr1: 1,
          per_streetaddr2: 1,
          per_placename: 1,
          per_stateorprov: 1,
          per_zipcode: 1,
          per_emailaddr: 1,
          per_phone: 1,
          per_notes: 1
        }
      });
    }
});

The insert code (which, again, is working), is:

Meteor.methods({
    'insertPerson': function(firstname, lastname, streetaddr1, streetaddr2, placename, stateorprov, zipcode, emailaddr, notes, phone) {
        console.log('insertPerson reached'); // TODO: Remove before deploying
        check(firstname, String);
        check(lastname, String);
        check(streetaddr1, String);
        check(streetaddr2, String);
        check(placename, String);
        check(stateorprov, String);
        check(zipcode, String);
        check(emailaddr, String);
        check(phone, String);
        check(notes, String);

        People.insert({
            per_firstname: firstname,
            per_lastname: lastname,
            per_streetaddr1: streetaddr1,
            per_streetaddr2: streetaddr2,
            per_placename: placename,
            per_stateorprov: stateorprov,
            per_zipcode: zipcode,
            per_emailaddr: emailaddr,
            per_phone: phone,
            per_notes: notes,
            per_createdBy: this.userId
        });
    }
});

What is preventing the fields from being returned and/or displayed?


#2

You have a mismatch between the template peopleGrid and the template helper main

if <template name="peopleGrid"> is a sub-template of <template name="main"> then you could just pass the cursor into peopleGrid

 {{> peopleGrid person=person}}

alternatively

put the person helper in Template.peopleGrid.helpers()