title: Getting exception after running pipeline: "can't convert from BSON type String to Date"
body: <p>I am getting an issue</p>
  
  <blockquote>
    <p>"can't convert from BSON type String to Date"</p>
  </blockquote>
  
  <p>for running the following aggregate query:  </p>
  
  <pre><code>db.test.aggregate(
  
      // Pipeline
      [
          // Stage 1
          {
              $match: {"Total Number Of CM": { $exists: true }}
          },
  
          // Stage 2
          {
              $project: {
                    _id : 0,
                    Date: { $dateToString: { format: "%Y-%m-%d", date: "$CollectionTime" } },
                    DeviceName: 1,
                    ResourceName: 1,
                    "Total Number Of CM": 1,
                    "Online Number Of CM": 1,
                    "Offline Number Of CM": 1,
              }
          },
  
          // Stage 3
          {
              $group: {
                  "_id": { Date: "$Date"},
                  ResourceName: { $first: "$ResourceName" },
                  DeviceName: { $first: "$DeviceName" },
                  TotalCM: { $avg: "$Total Number Of CM" },
                  OnlineCM: { $avg: "$Online Number Of CM" },
                  offlineCM: { $avg: "$offline Number Of CM" }
  
              }
          }
      ]
  );
  </code></pre>
  
  <p>Please, I need help to solve this issue. The sample looks like:</p>
  
  <pre><code>{
      "DeviceName" : "OLT0",
      "ResourceName" : "OLT/Frame:1/Slot:1/Port:0",
      "CollectionTime" : ISODate("2016-11-03T13:35:00.000+01:00"),
      "GranularityPeriod" : NumberLong("5"),
      "Total Number Of CM" : NumberLong("26"),
      "Online Number Of CM" : NumberLong("22"),
      "Offline Number Of CM" : NumberLong("4")
  }
  </code></pre>