title: The field must be an accumulator object. (The field is date string.)
body: <p><strong>I am trying to group by the date string and count how many data on each date.</strong> </p>
  
  <p>First I transfer the ISOdate to date string:</p>
  
  <pre><code>db.test.aggregate([
      {
          $project: {
                  yearMonthDay: { $dateToString: { format: "%Y-%m-%d", date: "$file_date" } }
          }
      },
  ])
  </code></pre>
  
  <p>The result:</p>
  
  <p><a href="https://i.stack.imgur.com/TjqxO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TjqxO.png" alt="nter image description here"></a></p>
  
  <p>So far so good until I do this:</p>
  
  <pre><code>db.closing_nassau.aggregate([
      {
          $project: {
                  yearMonthDay: { $dateToString: { format: "%Y-%m-%d", date: "$detail.file_date" } }
          }
      },
      { $group: { date: "$yearMonthDay", count: { $sum: 1 } } },
  ])
  </code></pre>
  
  <p>It keeps showing:</p>
  
  <blockquote>
    <p>"message" : "The field 'date' must be an accumulator object"</p>
  </blockquote>
  
  <p>I think this should work. I first transfer the ISOdate to date string. And I group by date string and count each date. I have tried removing <code>count: { $sum: 1 }</code> and it still shows the same error so the problem is on the group by.</p>
  
  <p>Feel free to ask further informations in order to help me.</p>