1. sort by date and camp id :
db.getCollection("ecstats").aggregate([{$group : {_id : {"Date" : { "$substr" : ["$Date", 0, 10] },"CampaignId":"$CampaignId"},ValidClk : {$sum : "$ValidClk"},ClkInvalid_total : {$sum : "$InvalidClk"}}}])
2. sort by ids before switch
db.getCollection("ecstats").aggregate([{$group : {_id : {"Date" : { "$substr" : ["$Date", 0, 10] },"AfOfferId":"$AfOfferId","ChannelId":"$ChannelId","AfProductId":"$AfProductId","AfLinkId":"$AfLinkId","ProductId":"$ProductId","OfferId":"$OfferId","LinkId":"$LinkId"},"AdvId":{$first : "$GroupId"},ValidClk : {$sum : "$ValidClk"},ClkInvalid_total : {$sum : "$InvalidClk"}}}])
3. sort for specified camp id without using match
st.aggregate([{"$group" : { "_id" : { "Date" : { "$substr" : ["$Date", 0, 10] }, "CampaignId" : "34" }, "ValidClk" : { "$sum" : "$ValidClk"{ "$sum" : "$InvalidClk" } }}])
4. 檢查點(diǎn)擊日志數(shù)量
db.getCollection('2017-11-10').find({"Availability" : true, "CampaignId" : "3", "AdvId" : 29, "ChannelId" : 2, "LinkId" : 23, "OfferId" : 35, "ProductId" : 30}).count()
5. 點(diǎn)擊日志分組統(tǒng)計(jì):
db.getCollection("2017-11-10").aggregate([{$group : {_id : {"ClickDay" : "$ClickDay","CampaignId":"$CampaignId","Availability" : "$Availability" },UniClkId : {$sum : 1},ClickId : {$sum : 1}}}])
6. ?bak:
db.getCollection("ecstats").aggregate([{$group : {_id : {"Date" : { "$substr" : ["$Date", 0, 10] },"AfOfferId":"$AfOfferId","ChannelId":"$ChannelId","AfProductId":"$AfProductId","AfLinkId":"$AfLinkId","ProductId":"$ProductId","OfferId":"$OfferId","LinkId":"$LinkId"},"AdvId":{$first : "$GroupId"},ValidClk : {$sum : "$ValidClk"},ClkInvalid_total : {$sum : "$InvalidClk"}}}])
db.getCollection("ecstats").aggregate([{$group : {_id : {"Date" : { "$substr" : ["$Date", 0, 10] },"CampaignId":"$CampaignId","AfOfferId":"$AfOfferId","ChannelId":"$ChannelId","AfProductId":"$AfProductId","AfLinkId":"$AfLinkId","ProductId":"$ProductId","OfferId":"$OfferId","LinkId":"$LinkId"},"AdvId":{$first : "$GroupId"},ValidClk : {$sum : "$ValidClk"},ClkInvalid_total : {$sum : "$InvalidClk"}}}])