title: Is it a bug to represent complex projection use spring data Aggregation
body: <p>My aggregation like that</p>
  
  <pre class="lang-js prettyprint-override"><code>db.data.aggregate(
  {
      "$project" : {
          "hour" : {"$hour" : "$time"},
          "_id" : 0,
          "time" : 1,
          "rawValue" : 1,
          "fid" : 1
      }
  },
  {
      "$group" : {
          "_id" : {"hour":"$hour","fid" : "$fid"},
          "maxTime" : {
              "$max" : "$time"
          },
          "minTime" : {
              "$min" : "$time"
          },
          "maxVal" : {
              "$max" : "$rawValue"
          },
          "minVal" : {
              "$min" : "$rawValue"
          }
      }
  },
  {
      "$project" : {
          "hour" : "$_id.hour",
          "_id" : 0,
          "value" : {
              "$divide" : [
                  {"$subtract":["$maxVal","$minVal"]},
                  {"$divide" : [{"$subtract" : ["$maxTime","$minTime"]},60 * 60 * 1000]}
              ]
          }
      }
  },
  {
      "$group" : {
          "_id" : "$hour",
          "avgH" : {
              "$sum" : "$value"
          }
      }
  },
  {
      "$sort" : {"_id" : 1}
  }
  )
  </code></pre>
  
  <p>This is the input document:</p>
  
  <pre class="lang-js prettyprint-override"><code>{
      "_id" : ObjectId("538408349aedda51a98a37f8"),
      "_class" : "ruijian.common.baseInfo.domain.FunctionValuePO",
      "fid" : "320102A002_01_0400_040000",
      "buildingid" : "320102A002",
      "time" : ISODate("2012-12-31T17:31:36Z"),
      "coding" : "01000",
      "rawValue" : 1691.2
  }
  </code></pre>
  
  <p>my java code</p>
  
  <pre><code>Aggregation aggregation = newAggregation(
          match(criteria),
          project("time","rawValue","fid").andExclude("_id")
                              .and("time").project("hour").as("hour"),
          group("hour","fid").max("time").as("maxTime")
                              .min("time").as("minTime")
                              .max("rawValue").as("maxVal")
                              .min("rawValue").as("minVal"),
          project().and("_id.hour").as("hour")
                              .andExpression("(maxVal - minVal) / ((maxTime - minTime) / (60 * 60 * 1000))").as("value")
                              .andExclude("_id"),
          group("hour").sum("value").as("avgH"),
          sort(Direction.ASC,"_id")
      );
  </code></pre>
  
  <p><strong>it was the 'andExpression("(maxVal - minVal) / ((maxTime - minTime) / (60 * 60 * 1000))")' that convert to mongodb expression is "$divide": [
                      {
                          "$subtract": [
                              "$maxVal",
                              "$minVal"
                          ]
                      },
                      {
                          "$subtract": [
                              "$maxTime",
                              "$minTime"
                          ]
                      },
                      {
                          "$multiply": [
                              60,
                              60,
                              1000
                          ]
                      }
                  ]</strong> </p>
  
  <p>the exception info is <em>[Command execution failed:  Error [exception: Expression $divide takes exactly 2 arguments. 3 were passed in.]</em>  </p>