【发布时间】:2022-01-20 07:54:48
【问题描述】:
在 MongoDB 聚合框架中,我希望在地图上使用 $unwind 运算符。看来是不可能了。
case class MatchStatus(
totalRows: Int,
fullMatch: Int,
noMatch: Int,
partialMatch: Int
)
这是我有 matchStatus => Map
{
"_id" : ObjectId("61e8c7bbd0597207179faa89"),
"clientId" : "DEMO",
"matchStatus" : {
"summary" : {
"totalRows" : "10",
"fullMatch" : "5",
"noMatch" : "1",
"partialMatch" : "4"
},
"income" : {
"totalRows" : "10",
"fullMatch" : "1",
"noMatch" : "0",
"partialMatch" : "1"
}
},
"date" : "18-01-2022"
},
{
"_id" : ObjectId("61e8c7bbd0597207179faa89"),
"clientId" : "DEMO-1",
"sizes" : [
"1",
"2"
],
"matchStatus" : {
"summary" : {
"totalRows" : "10",
"fullMatch" : "5",
"noMatch" : "1",
"partialMatch" : "4"
},
"income" : {
"totalRows" : "10",
"fullMatch" : "1",
"noMatch" : "0",
"partialMatch" : "1"
},
"slip" : {
"totalRows" : "10",
"fullMatch" : "1",
"noMatch" : "0",
"partialMatch" : "1"
},
},
"date" : "18-01-2022"
}
所以我想要的输出是 =>
{
"summary":{
"totalRows" : "20",
"fullMatch" : "10",
"noMatch" : "2",
"partialMatch" : "8"
},
"income":{
"totalRows" : "20",
"fullMatch" : "10",
"noMatch" : "0",
"partialMatch" : "2"
},
"slip":{
"totalRows" : "10",
"fullMatch" : "1",
"noMatch" : "0",
"partialMatch" : "1"
}
}
或类似的东西,我获取密钥(摘要、收入、单据)并汇总值。
尝试了 $unwind 但在地图结构上不起作用。
【问题讨论】:
标签: database mongodb nosql nosql-aggregation