【发布时间】:2017-02-09 03:41:27
【问题描述】:
我有一个嵌套在下面定义的层次结构中的 json 对象
[
{
"categoryId": 1,
"categoryName": "Category 1",
"childCategory": null,
"active": false
},
{
"categoryId": 2,
"categoryName": "Category 2",
"active": true,
"childCategory": [
{
"categoryId": 4,
"categoryName": "Category 4",
"childCategory": null,
"active": false
},
{
"categoryId": 5,
"categoryName": "Category 5",
"childCategory": null,
"active": true
}
]
},
{
"categoryId": 10,
"categoryName": "Category 10",
"childCategory": null,
"active": true
}
]
从此我想将所有活动类别选择到单个数组结构中。我的输出应该是
[
{
"categoryId": 2,
"categoryName": "Category 2",
"active": true
},
{
"categoryId": 5,
"categoryName": "Category 5",
"active": true
},
{
"categoryId": 10,
"categoryName": "Category 10",
"active": true
}
]
是否可以在单个查询语句中直接获取此数据。我正在为 mongodb 使用 spring 数据。
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework spring-data-mongodb