在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
group by date 聚合查询日期 统计每天数据(信息量) { "_id" : ObjectId("557ac1e2153c43c320393d9d"), "msgType" : "text", "sendTime" : ISODate("2015-06-12T11:26:26.000Z") } { "_id" : ObjectId("557ac1ee153c43c320393d9e"), "msgType" : "text", "sendTime" : ISODate("2015-06-12T11:26:38.000Z") } { "_id" : ObjectId("557ac2012de5d32d213963b5"), "msgType" : "text", "sendTime" : ISODate("2015-06-12T11:26:56.000Z") } { "_id" : ObjectId("557ac978bb31196e21d23868"), "msgType" : "text", "sendTime" : ISODate("2015-06-12T11:58:47.000Z") } { "_id" : ObjectId("557ac9afbb31196e21d23869"), "msgType" : "text", "sendTime" : ISODate("2015-06-12T11:59:43.000Z") } db.getCollection('wechat_message').aggregate( [ { $project : { day : {$substr: ["$sendTime", 0, 10] }}}, { $group : { _id : "$day", number : { $sum : 1 }}}, { $sort : { _id : -1 }} ] ) "result" : [ { "_id" : "2015-07-06", "number" : 13.0000000000000000 }, { "_id" : "2015-07-05", "number" : 3.0000000000000000 }, { "_id" : "2015-07-03", "number" : 10.0000000000000000 }, { "_id" : "2015-07-02", "number" : 29.0000000000000000 }, ]
coll.aggregate([ {$project:{sendDate: {$substr: ['$sendTime', 0, 10]}, sendTime: 1, content:1}}, {$match:{sendDate: '2015-07-05'}}, ]) coll.aggregate([ {$match: {'sendTime': {'$gte': new Date('2015-07-05'), '$lt': new Date('2015-07-06')}}} coll.aggregate([ {$match: {'sendTime': {'$gte': new Date('2015-07-05 00:00:00'), '$lte': new Date('2015-07-05 23:59:59')}}} 查询结果如下(展示一种方式:其他展示略有不同): [ { _id: 5599b09bc16aac90e9fb7995, sendDate: '2015-07-05' }, { _id: 5599b161c16aac90e9fb7996, sendDate: '2015-07-05' }, { _id: 5599b161c16aac90e9fb7997, sendDate: '2015-07-05' } ] |
请发表评论