【发布时间】:2019-01-01 19:20:26
【问题描述】:
我有类似的文档存储在 mongodb 中:
{
"_id" : ObjectId("----"),
"status" : "pending",
"user" : "huSWFekrPkw_xwtqDueAm4j4tHiuPJf3",
"type" : "inMemory",
"question" : "Hello, How are you?",
"intent" : "Greeting",
"createdAt" : ISODate("2018-07-24T06:33:59.399Z"),
"updatedAt" : ISODate("2018-07-24T06:33:59.399Z"),
}
{
"_id" : ObjectId("----"),
"status" : "trained",
"user" : "huSWFekrPkw_xwtqDueAm4j4tHiuPJf3",
"type" : "inMemory",
"question" : "Holla",
"intent" : "Greeting",
"createdAt" : ISODate("2018-07-25T06:33:59.399Z"),
"updatedAt" : ISODate("2018-07-25T06:33:59.399Z"),
}
{
"_id" : ObjectId("----"),
"status" : "trained",
"user" : "huSWFekrPkw_xwtqDueAm4j4tHiuPJf3",
"type" : "inMemory",
"question" : "want to talk with agent?",
"intent" : "Agent",
"createdAt" : ISODate("2018-07-26T06:33:59.399Z"),
"updatedAt" : ISODate("2018-07-26T06:33:59.399Z"),
}
我想要的聚合管道:
-
intent上的 $group -
status上的 $group - 根据这两组的结果,我想过滤每个特定意图的待定和训练数量。与 for
Greetingintent 一样,我有 2 个待处理文档和 1 个经过培训的文档。 - 稍后我还想要,
Greeting意图在今天、过去 7 天或上个月有多少文档。
所以最终的文档会是这样的:
{
"intent" : "Greeting",
"status_pending" : 1,
"status_trained" : 2,
"last_day" : 1,
"last_seven_day" : 3,
"last_month" : 7
}
{
"intent" : "Agent",
"status_pending" : 1,
"status_trained" : 1,
"last_day" : 1,
"last_seven_day" : 2,
"last_month" : 3
}
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework