title: Jade - Trying display collection data from mongodb
body: <p>i want to display data from mongodb collection</p>
  
  <p>i am using pug for and want to display my data collection in mongodb</p>
  
  <p>but i have no idea, about this error</p>
  
  <p>i have tried this</p>
  
  <p>it's my .pug file</p>
  
  <pre><code>extends layout
  
  block content
      if registrations.length
          table
              tr
                  th Name
                  th Email
              each registration in registrations
                  tr
                      td=registration.name
                      td=registration.email
      else
          p No registrations yet
  </code></pre>
  
  <p>it's my index.js file</p>
  
  <pre><code>
  const Registration = mongoose.model('Registration');
  router.get('/registrations', (req, res) =&gt; {
      Registration.find()
          .then((registrations) =&gt; {
              res.render('index', { title: 'Listing registrations' });
          })
          .catch(() =&gt; { res.send('Something went wrong'); });
  });
  </code></pre>
  
  <p>it's the error message</p>
  
  <pre><code>TypeError: E:\web_apps_project\demo-node-app\views\index.pug:4
      2| 
  
      3| block content
  
    &gt; 4|     if registrations.length
  
      5|         table
  
      6|             tr
  
      7|                 th Name
  
  
  Cannot read property 'length' of undefined
      at eval (eval at wrap (E:\web_apps_project\demo-node-app\node_modules\pug-runtime\wrap.js:6:10), &lt;anonymous&gt;:21:19)
      at template (eval at wrap (E:\web_apps_project\demo-node-app\node_modules\pug-runtime\wrap.js:6:10), &lt;anonymous&gt;:79:50)
      at Object.exports.renderFile (E:\web_apps_project\demo-node-app\node_modules\pug\lib\index.js:427:38)
      at Object.exports.renderFile (E:\web_apps_project\demo-node-app\node_modules\pug\lib\index.js:417:21)
      at View.exports.__express [as engine] (E:\web_apps_project\demo-node-app\node_modules\pug\lib\index.js:464:11)
      at View.render (E:\web_apps_project\demo-node-app\node_modules\express\lib\view.js:135:8)
      at tryRender (E:\web_apps_project\demo-node-app\node_modules\express\lib\application.js:640:10)
      at Function.render (E:\web_apps_project\demo-node-app\node_modules\express\lib\application.js:592:3)
      at ServerResponse.render (E:\web_apps_project\demo-node-app\node_modules\express\lib\response.js:1012:7)
      at Registration.find.then (E:\web_apps_project\demo-node-app\routes\index.js:36:17)
      at process._tickCallback (internal/process/next_tick.js:68:7)
  </code></pre>