title: How can I get a substring of the strings returned from a foreach loop in Node.js when connected to MongoDB Atlas
body: <p>Problem: .substring() does not process when I connect my code to MongoDB Atlas.</p>
  
  <p>Background:
  I'm new to coding and I am creating a blog where I need to render the posts to a blog route and to a dynamic route using route parameters and the posts need to be saved to a MongoDB Atlas server. 
  I need to show only the first 100 characters in each post and then lead the user to another page using a "Read More" link.
  When I use localhost:3000 to render the data, the blog posts are successfully truncated using .substring(0, 100), but when I connect to MongoDB Atlas the error message "Cannot read property 'substring' of undefined." If I remove .substring() everything processes properly so is there another way of truncating the strings?</p>
  
  <p>I couldn't find much online but so far I have tried MongoDB's $substrBytes and $substr(deprecated).</p>
  
  <pre><code>&lt;% posts.forEach(function(post) { %&gt;
      &lt;!-- Render the postTitle value as the title of the journal entry --&gt;
      &lt;h2&gt;&lt;%= post.title %&gt; &lt;/h2&gt;
      &lt;p&gt;
      &lt;!-- Render the postBody value and truncate the blog post to 100 
      characters --&gt;
      &lt;%= post.content.substring(0, 100) + '...'%&gt;
      &lt;!-- Add a link to see the full blog post on a separate page --&gt;
      &lt;a href="/posts/&lt;%= post._id %&gt;"&gt;Read More&lt;/a&gt;
      &lt;/p&gt;
      &lt;% }) %&gt;
  </code></pre>
  
  <p>Expected results: ...Read More
  Actual results: TypeError:...\blog.ejs. Cannot read property 'substring' of undefined</p>