title: Passing in data from Mongodb to HTML table using javascript using Node.js framework
body: <p>I'm quite new at using node.js. Right now I'm trying to pull data from MongoDB and display it in a table using Javascript + HTML. However, my table is populating with undefined in all the fields. I think something is definitely wrong with how I'm reading data through to the Javascript function b/c I am able to render the full results from the people.js file straight to the webpage. Thank you in advance!! Below is my code:</p>
  
  <p>Code for my people.js file:</p>
  
  <pre><code>exports.getPeople = (req, res) =&gt; {
    People.find((err, docs) =&gt; {
      if (err) { return next(err); }
      if (docs != null){
       console.log(docs.length)
       docs.forEach(function(docs, index) {
       console.log(index + " key: " + docs.name)
         });
       res.render('people', { people: docs });
      }
     else{
      res.render('people', { people: docs() });
     }
   });
  };
  </code></pre>
  
  <p>My Javascript + HTML that's populating my webpage.</p>
  
  <pre><code>  script(type='text/javascript', src='http://code.jquery.com/jquery-1.9.1.js', charset='UTF-8')
    script.
      $(document).ready(function(){
        var obj=  '$(people)'
  
        var tbl = "&lt;table&gt;"
        var content="";
        for(i=0; i&lt;obj.length;i++){
          content +=
            '&lt;tr&gt;+&lt;td&gt;' +obj[i]["name"]+
            '&lt;/td&gt;&lt;td&gt;'+obj[i]["type"]+
            '&lt;/td&gt;&lt;td&gt;'+obj[i]["min_hours"]+
            '&lt;/td&gt;&lt;td&gt;'+obj[i]["max_hours"]+
            '&lt;/td&gt;&lt;td&gt;'+obj[i]["email"]+
            '&lt;/td&gt;&lt;td&gt;'+obj[i]["phone_number"]+
            '&lt;/td&gt;&lt;td&gt;'+ '&lt;input type="button" value = "Update" onClick="Javacsript:deleteRow(this)"&gt;' +
            '&lt;/td&gt;&lt;td&gt;'+'&lt;input type="button" value = "Delete" onClick="Javacsript:deleteRow(this)"&gt;';
            '&lt;/td&gt;&lt;/tr&gt;';
          }
        content += "&lt;/table&gt;"
        $('#myTableData').append(content);
      });
  </code></pre>