group with multiple ids and sum in mongodb -


{             "_id" : objectid("59774aa87da165f360b0271a"),             "createddate" : isodate("2017-07-25t13:42:00.000z"),             "sourceid" : objectid("000000000000000000000000"),             "fanclubid" : objectid("59774aa87da165f360b02719"),             "coins" : -500,             "reasonid" : objectid("593500980b0cbbe593cd722c"),             "userid" : objectid("597731d3ee99e33e1696de79")         }          {             "_id" : objectid("59784c76e8288e1be6dace64"),             "createddate" : isodate("2017-07-26t08:01:58.000z"),             "sourceid" : objectid("000000000000000000000000"),             "fanclubid" : objectid("59784c76e8288e1be6dace63"),             "coins" : -500,             "reasonid" : objectid("593500980b0cbbe593cd722c"),             "userid" : objectid("597731d3ee99e33e1696de79")         }          {             "_id" : objectid("597734e376f9e53e0e52588a"),             "createddate" : isodate("2017-07-25t12:09:07.000z"),             "sourceid" : objectid("000000000000000000000000"),             "fanclubid" : objectid("000000000000000000000000"),             "coins" : 5,             "reasonid" : objectid("593501ff0b0cbbe593cd7236"),             "userid" : objectid("597731d3ee99e33e1696de79")         }          db.getcollection('fancoins').aggregate([{$group : {_id:{userid:objectid("597731d3ee99e33e1696de79"),         reasonid:objectid("593500980b0cbbe593cd722c")},coins:{$sum : { $add: ["$coins"]}}}} ]) 

i used query result sum of coins of userid & reasonid, i'm getting total sum of userid's. how in mongodb group by.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -