title: mongoDB query result
body: <p>I am learning mongodb.I have a document which looks like this:</p>
  
  <pre><code>{
  "_id" : ObjectId("558bb3490e98e0108940afee"),
  "term" : "nike team court graphic  mens tennis  crew and shorts",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 15
  }
  {
  "_id" : ObjectId("558bb3500e98e0108940afef"),
  "term" : "nike team court graphic  mens tennis  crew and shorts",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 12
  }
  {
  "_id" : ObjectId("558bb3550e98e0108940aff0"),
  "term" : "nike team court graphic  mens tennis  crew and shorts",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 18
  }
  {
  "_id" : ObjectId("558bb3640e98e0108940aff1"),
  "term" : "nike",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 18
  }
  {
  "_id" : ObjectId("558bb3680e98e0108940aff2"),
  "term" : "nike",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 12
   }
   {
  "_id" : ObjectId("558bb36b0e98e0108940aff3"),
  "term" : "nike",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 13
  }
  {
  "_id" : ObjectId("558bb3720e98e0108940aff4"),
  "term" : "nike",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 10
  }
  {
  "_id" : ObjectId("558bb3790e98e0108940aff5"),
  "term" : "nike1",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 10
  }
  {
  "_id" : ObjectId("558bb37e0e98e0108940aff6"),
  "term" : "nike1",
  "year" : "2015",
  "month" : "06",
  "day" : "06",
  "hour" : "12",
  "count" : 111
  }
  {
      "term" : "nike1",
      "year" : "2014",
      "month" : "03",
      "day" : "07",
      "count" : 110
  }
  </code></pre>
  
  <p>I want to perform aggregation in such a way that it returns the <strong>term</strong> , <strong>year</strong> , <strong>month</strong> , <strong>day</strong> and <strong>sum of total count</strong> based on the match of term,year,month and day.</p>
  
  <p><strong>My query</strong> </p>
  
  <pre><code>db.products.group( {
  $match:{$and:[{year:"2015"},{month:"06"},{day:"06"}]},
  key: {  term: "$term", year: "2015", month : "06", day : "06" },
  reduce: function(cur, result) { result.count += cur.count },
  initial: { count: 0 }
  } )
  </code></pre>
  
  <p>The output I am getting:</p>
  
  <pre><code>[
  
  {
      "term" : "nike team court graphic  mens tennis  crew and shorts",
      "year" : "2015",
      "month" : "06",
      "day" : "06",
      "count" : 45
  },
  {
      "term" : "nike",
      "year" : "2015",
      "month" : "06",
      "day" : "06",
      "count" : 53
  },
  {
      "term" : "nike1",
      "year" : "2015",
      "month" : "06",
      "day" : "06",
      "count" : 121
  },
  {
      "term" : "nike1",
      "year" : "2014",
      "month" : "03",
      "day" : "07",
      "count" : 110
  }
  ]
  </code></pre>
  
  <p>The last result is not expected</p>
  
  <pre><code>{
      "term" : "nike1",
      "year" : "2014",
      "month" : "03",
      "day" : "07",
      "count" : 110
   } 
  </code></pre>
  
  <p>since the year,month and day doesn't full fill the condition which i passed.
  I know i am missing something.Can anyone please point it out ?</p>