【发布时间】:2023-03-24 19:58:01
【问题描述】:
集合由日志数据组成。
日志
[
{ "Module": "Admin",
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Admin",
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Home",
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Admin",
"UserEmail": "santa@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Contact",
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Contact",
"UserEmail": "santa@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Admin",
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" },
{ "Module": "Home",
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00" }
]
预期结果
[
{
"Module": "Admin",
"Count":4,
"Logs": [
{
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
},
{
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
},
{
"UserEmail": "santa@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
},
{
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
}
]
},
{
"Module": "Home",
"Count":2,
"Logs": [
{
"UserEmail": "ricky@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
},
{
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
}
]
},
{
"Module": "Contact",
"Count":2,
"Logs": [
{
"UserEmail": "tony@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
},
{
"UserEmail": "santa@dne.com",
"Completed": "2020-02-29T01:21:24.128+00:00"
}
]
}
]
需要对日志进行聚合以获取模块的使用计数和基于用户的时间序列 grpah 以获得额外信息。预期结果将用于从 chartjs 绘制折线图。
在 c# mongodb 客户端中寻找为上述问题构建的聚合管道。
【问题讨论】:
-
这就是使用
$group的东西。 -
有this,但看起来你想要一个特定于mongodb的解决方案。
-
这很好用。只需要从这里创建一个 mongo 聚合管道
标签: c# mongodb aggregation-framework pipeline