Double Array with NaN values - $sum , $avg,$min returns NaN results but not $max

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Environment:
      Mongo 3.2 and Mongo 3.4
    • Query
    • Fully Compatible
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have document in the similar structure to hold a 5 minutely values in a document.

      Document structure:

      { 
          "_id" : ObjectId("5857f58d396adf19c41a3f14"), 
          "source" : "LONDON.CITY.ALL", 
          ""uIndex" : ISODate("2016-01-01T00:00:00.000+0000"), 
          "values" : {
              "0" : [NaN, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0], 
              "1" : [13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0],
      		.....
      		....
      	"23" : [277.0, 278.0, 279.0, 280.0, 281.0, 282.0, 283.0, 284.0, 285.0, 286.0, 287.0, 288.0      ]
            }
      }
      

      I am doing an hourly aggregation to find min , max, average, sum per hour . One of the values is NaN.

      Aggregation returns the following results

      Aggregation Query :

      db.City.aggregate([
                                                           {
                                                             $match:{"source":LONDON.CITY.ALL"}
                                                           },
                                                           
                                                          
                                                          {$unwind:"$values.0"}, 
                                                
                                                          {$group : { _id :"$source", sum:{$sum:"$values.0"},avg:{$avg:"$values.0"},max:{$max:"$values.0"},min:{$min:"$values.0"}}}
                                                          
                                                                                           
                                                      ])
      

      Aggregation results:

      Sum: NaN
      Avg:NaN
      Max: 12
      Min:Nan

      Question is :

      1. Why is Sum , average ,Min operators returning Nan but Max is returning the maximum of that array "0" : [NaN, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0] ?
      2. How do we handle NaN in case of a double array

      Should All operators should not behave in a similar way.?

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            Kowshik [X]
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: