title: Running a forEach loop in Mongoose, in reverse
body: <p>I'm currently trying to make a faux blog style page. All the relevant information is in MongoDB and I'm extracting it using a forEach loop. </p>
  
  <pre><code>`&lt;% blogs.forEach(function(blog){ %&gt;
     &lt;img src="&lt;%= blog.image %&gt;" &gt;
     &lt;a href="/blogs/&lt;%= blog._id%&gt;"&gt;&lt;%=blog.title%&gt;&lt;/a&gt;
    &lt;span&gt;&lt;%= blog.created.toDateString() %&gt;&lt;/span&gt;
    &lt;p&gt;&lt;%- blog.body.substring(0, 100) %&gt;...&lt;/p&gt;
     &lt;% }) %&gt;`
  </code></pre>
  
  <p>The database contains these objects when you create/edit a post. When you run a forEach it will start at the beginning of the database and then work forwards. I'm trying to figure out how to make it go in reverse as a typical blog site will push older posts down the page when new content is posted (as of now it's displaying the first post first, second one second, etc.)</p>
  
  <p>I thought about creating a for loop and constraining the length of it by using the .count() mongoose command but I can't seem to figure out how I can relate it the various objects in the database. Basically I'm trying to convert this forEach to use a variable (like [i]). </p>