我有一个复杂的文档结构,如下所示 -
{
"Application": {
"DEF": {
"Year": {
"2018": {
"Quarter": {
"Q1": {
"Microservice": [ "A", "B" ]
},
"Q2": {
"Microservice": [ "C", "D" ]
},
"Q3": {
"Microservice": [ "E" ]
},
"Q4": {
"Microservice": [ "F", "G" ]
}
}
},
"2019": {
"Quarter": {
"Q1": {
"Microservice": [ "A", "C" ]
},
"Q2": {
"Microservice": [ "D" ]
},
"Q3": {
"Microservice": [ "E", "F" ]
},
"Q4": {
"Microservice": [ "G" ]
}
}
}
}
}
},
"Product Name": "XYZ"
}
我正在尝试查询 Application 为 DEF、Year 为 2018 和所有 Quarters 的所有记录。我已经尝试过如下的 DOT(.) 表示法——
db.productsTest.find({"Application.DEF.Year.2018": {$exists: true}})
以上返回所有年份(2018 年和 2019 年)的结果,而不是仅返回 2018 年的年份、季度和微服务组合。这也可能是因为 JSON 结构,我无法按年份过滤(因为它们是嵌套的) . 基本上我正在寻找返回这个的查询——
{
"Application": {
"DEF": {
"Year": {
"2018": {
"Quarter": {
"Q1": {
"Microservice": [ "A", "B" ]
},
"Q2": {
"Microservice": [ "C", "D" ]
},
"Q3": {
"Microservice": [ "E" ]
},
"Q4": {
"Microservice": [ "F", "G" ]
}
}
}
}
}
},
"Product Name": "XYZ"
}
考虑到我的 JSON 结构,这个结果是否可能?