I have documents similar to this stored in 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"),
}
Aggregation pipelines I want :
- $group on
intent - $group on
status - On the basis of the result of these two groups, I want to filter how many are pending and trained for every particular Intent. Like for
Greetingintent, I have 2 pending document and 1 trained document. - Later I also want, How many documents for
Greetingintent in today, last 7 days or last month.
So the final document will be something looks like :
{
"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
}