Add static field to grouped data in Mongodb -


how add static field result using group operation in mongodb. query looks like:

db.sales.aggregate({     $group : {         _id: {             year: { $year: '$date' },         },         amount: { $sum: 1 }     } }); 

than result:

{     "result" : [         {             "_id" : {                 "year" : 2013             },             "amount" : 43433         },         ...     ]     "ok" : 1 } 

i need add field called type value 'year' in each object of result.

i need add project operation literal 'year'. query looks like:

db.sales.aggregate([ {     $group : {         _id: {             year: { $year: '$registrationdate' }         },         amount: { $sum: 1 }     }, }, {          $project: {                 type: { $literal: 'year' },          }     }  ]); 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -