title: Iterate mongoose object with EJS
body: <p>When i put <code>&lt;%= products %&gt;</code> into my view, it prints [Object Object] so I'm assuming that the mongoose resultset is an object. Now, I am trying to loop over <code>products</code> object but it says <code>products.forEach is not a function</code>.</p>
  
  <p>This is my <code>index route</code>: </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var express = require('express');
  var router = express.Router();
  var Product = require('../model/product');
  
  /* GET home page. */
  router.get('/', function(req, res, next) {
    var products = Product.find();
    res.render('index', { title: 'Express', products: products });
  });
  
  module.exports = router;</code></pre>
  </div>
  </div>
  </p>
  
  <p>with the code above,I am just retrieving it from the db and passing it as an object. I have tried using <code>var products = Product.find({}).toArray();</code> but got no luck. And another solution I tried is using this code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>  var products = Product.find();
    var data = JSON.stringify(products);
    res.render('index', { title: 'Express', products: data });</code></pre>
  </div>
  </div>
  
  but I am getting the infamous <code>Converting circular structure to JSON</code>error.</p>
  
  <p>This is my <code>index view</code>:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;&lt;%= title %&gt;&lt;/title&gt;
      &lt;link rel='stylesheet' href='/stylesheets/style.css' /&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;h1&gt;&lt;%= title %&gt;&lt;/h1&gt;
    &lt;p&gt;Welcome to &lt;%= title %&gt;&lt;/p&gt;
  
    &lt;% products.forEach(function(product) { %&gt;
     &lt;p&gt;&lt;%= product.title %&gt;&lt;/p&gt;
    &lt;% }); %&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  
  lastly this is my <code>Product Schema</code>:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var schema = new Schema({
   imagePath: { type: String, required: true },
   title: { type: String, required: true },
   description: { type: String, required: true },
   price: { type: Number, required: true }
  });
  
  module.exports = mongoose.model('Product', schema);</code></pre>
  </div>
  </div>
  </p>
  
  <p>How is the proper way of doing it?</p>