mongoDB query Result Output -


i have following documents in collection:

{     "_id" : objectid("539c118b310c022c947b0055"),     "term" : "aero storm tour",     "year" : "2015",     "month" : "06",     "day" : "01",     "hour" : "17",     "dayofyear" : "4",     "weekofyear" : "22",     "productcount" : 0,     "count" : 22 }, {     "_id" : objectid("558c118b310c022c947b1145"),     "term" : "aero",     "year" : "2015",     "month" : "06",     "day" : "01",     "hour" : "17",     "dayofyear" : "4",     "weekofyear" : "22",     "productcount" : 0,     "count" : 21 }, {     "_id" : objectid("558c992b310c022c947b0055"),     "term" : "aero storm tour",     "year" : "2015",     "month" : "06",     "day" : "01",     "hour" : "17",     "dayofyear" : "1",     "weekofyear" : "22",     "productcount" : 0,     "count" : 2 }, {     "_id" : objectid("558c118b123c022c947b0055"),     "term" : "aero storm tour",     "year" : "2014",     "month" : "06",     "day" : "01",     "hour" : "17",     "dayofyear" : "364",     "weekofyear" : "22",     "productcount" : 0,     "count" : 32 }, {     "_id" : objectid("558c223c310c022c947b0055"),     "term" : "aero storm tour",     "year" : "2014",     "month" : "06",     "day" : "01",     "hour" : "17",     "dayofyear" : "365",     "weekofyear" : "22",     "productcount" : 0,     "count" : 22 } 

i need calculate sum of count , termbased on condition specified year , dayofyear .

my query :

db.tq.aggregate(    {$match:       {$or :[             { $and :[{dayofyear:{ $gte : "1", $lte : "4" }},{year : "2015"}]},             { $and :[{dayofyear:{ $gte : "363", $lte : "365" }},{year : "2014"}]}             ]       }     },       {$group:{                 _id :"$term",        totalcount : {                      $sum : "$count"                     }    }  },  { $sort : {totalcount : -1}  }  ) 

here , have manually specified dayofyear between 1 & 4 year 2015 , dayofyear 363 & 365 year 2014.

but not give desired result. can 1 point out mistake in query ?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -