我是MongoDB的新手,想知道如何计算从UTC时间12 AM到当前UTC时间每15分钟间隔插入集合中的文档总数。
以下是样本文件
{
"_id" : ObjectId("5ade8bfc6b941c7726a54f01"),
"Country" : "US"
"Timestamp" : ISODate("2018-04-24T01:44:28.040Z"),
}
这是预期的输出:
{
"Count": 245,
"ReceiveDateString": "5/2/2018 12:00:00 AM"
},
{
"Count": 239,
"ReceiveDateString": "5/2/2018 12:15:00 AM"
},
{
"Count": 252,
"ReceiveDateString": "5/2/2018 12:30:00 AM"
},
{
"Count": 255,
"ReceiveDateString": "5/2/2018 12:45:00 AM"
},
{
"Count": 242,
"ReceiveDateString": "5/2/2018 1:00:00 AM"
}
.
.
.
and so on until current UTC time.
我可以按分钟分组,如下所示:
var filter = Builders<Model>.Filter.Where(r => r.Timestamp > startDate && r.Timestamp < endDate);
var result = Collection.Aggregate()
.Match(filter)
.Group(
r => r.Timestamp.Minute,
g => new
{
ReceiveDate = g.Select(x => x.Timestamp).First(),
Count = g.Count(),
}
).ToEnumerable();
但是,我无法弄清楚如何将MongoDb中按15分钟的时间间隔在Group result中提供的解决方案转换为MongoDB C#驱动程序查询。
相关分类