mongodb 聚合查询每天论坛链接点击次数

/* 18 */
{
    "_id" : ObjectId("5596414cbe4d73a327e50274"),
    "msgType" : "text",
    "sendTime" : ISODate("2015-07-03T08:01:16.000Z")
}

/* 19 */
{
    "_id" : ObjectId("5596414cbe4d73a327e50275"),
    "msgType" : "text",
    "sendTime" : ISODate("2015-07-03T08:01:16.000Z")
}

/* 20 */
{
    "_id" : ObjectId("55964179a29582f427335cff"),
    "msgType" : "text",
    "sendTime" : ISODate("2015-07-03T08:02:01.000Z")
}

/* 21 */
{
    "_id" : ObjectId("559641aba29582f427335d01"),
    "msgType" : "text",
    "sendTime" : ISODate("2015-07-03T08:02:51.000Z")
}

/* 22 */
{
    "_id" : ObjectId("553ae47bd1ba636729be4106"),
    "msgType" : "text",
    "sendTime" : ISODate("2015-04-25T00:48:59.000Z")
}


// Group Sql here
db.getCollection('wechat_message').aggregate(
    [         
        {   $group   : { _id : {$dayOfYear: "$sendTime"},  click : { $sum : 1 }}},
        {   $sort    : { _id : -1 }}        
    ]
)


// Result here
{
            "_id" : 178,
            "click" : 8.0000000000000000
        }, 
        {
            "_id" : 177,
            "click" : 21.0000000000000000
        }, 
        {
            "_id" : 176,
            "click" : 32.0000000000000000
        }, 
        {
            "_id" : 175,
            "click" : 16.0000000000000000
        }, 
        {
            "_id" : 174,
            "click" : 8.0000000000000000
        }, 
        {
            "_id" : 173,
            "click" : 7.0000000000000000
        }, 
        {
            "_id" : 172,
            "click" : 8.0000000000000000
        }, 

 

你可能感兴趣的:(每天进步一点点,学习永无止境,mongodb,纵观千象)