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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -