$ substr聚合函数mongodb中的计数不匹配

时间:2016-10-22 05:24:12

标签: regex mongodb mongodb-query mongodb-aggregation

我有一些数据,其中ISO日期被存储为字符串,我正在运行$ substr来获取计数Match with substring in mongodb aggregation 但计数不匹配日复一日。无法弄清楚原因。数据库在mlab.com中,它存储了UTC和我在IST上运行的代码..这是否会导致不匹配? 计划使用$ regex但没有得到如何

数据就像

{"_id": {"$oid": "580af4ce1b407e114sdvsdbf"},
    "isActive": "1",
    "createdAt": "2016-10-22T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407safasfe114bf"},
    "isActive": "1",
    "createdAt": "2016-10-22T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495sagfdgaed"},
    "isActive": "1",
    "createdAt": "2016-10-21T05:10:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f4956436sdg"},
    "isActive": "1",
    "createdAt": "2016-10-20T05:30:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495safasgvd"},
    "isActive": "1",
    "createdAt": "2016-10-10T05:05:38.632Z",
},
{"_id": {"$oid": "580af4ce1b407f495325ds"},
    "isActive": "1",
    "createdAt": "2016-10-10T08:10:38.632Z",
}

我的查询是

var data = db.userprofiles.aggregate(
    [   
        {   $match:  { isActive: "1"} },
        {   $project : { day : {$substr: ["$createdAt", 0, 10] } }},        
        {   $group   : { _id : "$day",  number : { $sum : 1 }}},
        {   $sort    : { _id : 1 }}        
    ]
) 

有人可以帮我解决这个计数不匹配问题吗?

0 个答案:

没有答案