MongoDb

Clickstream Report

Sample Data:
-------------------
db.MarketingClickStream.find();
{ "_id" : ObjectId("536bf6b2820e4"), "source" : "mwb0791", "email" : "abc@gmail.com", "dpn" : 9884403 }
{ "_id" : ObjectId("536bfdae8de40"), "source" : "mwb0791", "email" : "abc@gmail.com", "dpn" : 9884403 }
{ "_id" : ObjectId("536bf088de403"), "source" : "mwb0791", "email" : "abc@gmail.com", "dpn" : 9884403 }
{ "_id" : ObjectId("536b088de4037"), "source" : "mwb0791", "email" : "test@gmail.com", "dpn" : 9884403 }
 
 
This will not solve duplicates (but gives total clicks for Item Id [dpn])...
db.MarketingClickStream.aggregate(
   {"$match":{"source": "mwb0791"}}, 
   {"$group":{
    "_id":"$dpn", 
    "unique":{$sum:1}
   }} 
)
 
This will not solve unique clicks...
db.MarketingClickStream.aggregate(
   {"$match":{"source": "mwb0791"}}, 
   {"$group":{
    "_id": {dpn: "$dpn", email: "$email"}, 
    "unique":{$sum:1}
   }},
   {"$group":{
"_id":"$_id.dpn",
"unique":{$sum:1}
   }}
)