title: mongodb how to query sum string?
body: <p>I have some data in <code>order</code> document like:</p>
  
  <pre><code>{ "_id": "...", "orderTotal": { "amount" : "10.99", "unit": "USD"}, "orderTime": "...", ... }
  { "_id": "...", "orderTotal": { "amount" : "9.99", "unit": "USD"}, "orderTime": "...",  ... }
  { "_id": "...", "orderTotal": { "amount" : "8.99", "unit": "USD"}, "orderTime": "...",  ... }
  </code></pre>
  
  <p>I want to query the orderTotal of all orders group by day:</p>
  
  <pre><code>db.getCollection('order').aggregate([
    {
      '$group' : {
          '_id': { day: { $dayOfMonth: "$orderTime"}, month: {$month: "$orderTime"}, year: { $year: "$orderTime" }},
          'totalAmount': { $sum: '$itemTotal.amount' },
          'count': { $sum: 1 }
      }
    }
  ])
  </code></pre>
  
  <p>but got:</p>
  
  <pre><code>{
      "_id" : {
          "day" : 12,
          "month" : 12,
          "year" : 2016
      },
      "totalAmount" : 0,
      "count" : 4607.0
  }
  </code></pre>
  
  <p>the <code>amount</code> is a string. Use <code>parseFloat</code> but got NaN.</p>
  
  <pre><code>db.getCollection('order').aggregate([
    {
      '$group' : {
          '_id': { day: { $dayOfMonth: "$orderTime"}, month: {$month: "$orderTime"}, year: { $year: "$orderTime" }},
          'totalAmount': { $sum: parseFloat('$itemTotal.amount') },
          'count': { $sum: 1 }
      }
    }
  ])
  </code></pre>
  
  <p>got </p>
  
  <pre><code>{
      "_id" : {
          "day" : 12,
          "month" : 12,
          "year" : 2016
      },
      "totalAmount" : NaN,
      "count" : 4607.0
  }
  </code></pre>
  
  <p>I can't update the <code>order</code> document to change <code>itemTotal.amount</code> to float like other questions said:</p>
  
  <pre><code>db.order.find().forEach(function(data) {
      db.order.update({
          "_id": data._id,
          "itemTotal.amount": data.itemTotal.amount
      }, {
          "$set": {
              "itemTotal.amount": parseFloat(data.itemTotal.amount)
          }
      });
  })
  </code></pre>
  
  <p>I have no permissions to do this.
  So, how can I get the sum by day? </p>