Tag: 聚合框架

在Mongodb中按日期汇总

我正在编写一个function,我需要按日期分组。 这是我目前的做法: //Assuming this is my sample document in the collection { “_id” : ObjectId(“56053d816518fd1b48e062f7”), “memberid” : “7992bc31-c3c5-49e5-bc40-0a5ba41af0bd”, “sourceid” : NumberInt(3888), “ispremium” : false, “createddate” : { “DateTime” : ISODate(“2015-09-25T12:26:41.157+0000”), “Ticks” : NumberLong(635787808011571008) }, “details”: { //a large sub-document } } 给定会员ID,开始日期和结束日期; 我需要搜索与这些filter匹配的集合,并按日期对结果进行分组。 换句话说,我需要实现的结果是一个列表(例如,2015年12月10日 – 计数是5,13 / 10/2015 – 计数是2)。 StartDate和EndDate是DateTime的类型。 C#是我使用的编程语言,目前我写的方式是: var builder = […]

使用C#计算嵌套对象的数量

我正在使用ASP.Net core 2.0 web api开发一个软件。 我需要计算我的集合中某些字段的数量。 我在MongoDB的集合中有数据,如下所示。 我需要找到我的collections中有多少个标签和多少个传感器。 特定端点具有多个标签,每个标签具有多个传感器。 { “_id” : ObjectId(“5aef51dfaf42ea1b70d0c4db”), “EndpointId” : “89799bcc-e86f-4c8a-b340-8b5ed53caf83”, “DateTime” : ISODate(“2018-05-06T19:05:02.666Z”), “Url” : “test”, “Tags” : [ { “Uid” : “C1:3D:CA:D4:45:11”, “Type” : 1, “DateTime” : ISODate(“2018-05-06T19:05:02.666Z”), “Sensors” : [ { “Type” : 1, “Value” : NumberDecimal(“-95”) }, { “Type” : 2, “Value” : NumberDecimal(“-59”) }, { […]