我正在尝试编写 Couchbase 查询以从下面给出的 JSON 中获取结果。 我正在使用 UNNEST 操作,但不知何故没有得到预期的结果。
我们可以在一个查询中使用多个 UNNEST 吗?如果是,那么我的查询有什么问题?
输入如下 JSON,
{
"country": "India",
"id": "1111",
"value": {
"isDefault": false,
"schedules": {
"default": {
"startTime": null,
"flightConfigs": {
"1M": {
"1": {
"airlineid": "airline_5201",
"destinationairport": "SFO",
"name": "United Airlines",
"sourceairport": "ABQ"
},
"2": {
"airlineid": "airline_5202",
"destinationairport": "SFO",
"name": "United Airlines",
"sourceairport": "ACV"
}
}
},
"2M": {
"1": {
"airlineid": "airline_5203",
"destinationairport": "SFO",
"name": "United Airlines",
"sourceairport": "ABQ"
},
"2": {
"airlineid": "airline_5204",
"destinationairport": "SFO",
"name": "United Airlines",
"sourceairport": "ACV"
}
}
}
}
}
}
我的预期输出如下:
[
{
"id": "1111",
"schedule": "default",
"month": "1M"
},
{
"id": "1111",
"schedule": "default",
"month": "2M"
}
]
我正在尝试查询,但没有得到预期的结果,
选择 data.id 作为 id,sched_n 作为时间表,month 作为月份 来自 AIR_CONFIG.SCHEDULE.Flight_Schedule 数据 取消嵌套 OBJECT_NAMES(data.
.schedules) 作为 sched_n 按计划取消嵌套 OBJECT_INNER_VALUES(data.value
.schedules) 将 OBJECT_NAMES(sched.flightConfigs) 解除嵌套为月份 其中 data.id 如“1111”value
有人可以帮忙吗?
谢谢
我得到了答案,
我们可以使用单独的 UNNSET 来读取名称和值 取消嵌套对象对
选择 data.id 作为 id,sched_n.name 作为时间表,month.name 作为月份 AIR_CONFIG.SCHEDULE.Flight_Schedule 数据 UNNEST OBJECT_PAIRS(data.value.schedules) 作为 sched_n UNNEST OBJECT_PAIRS(sched.flightConfigs) 作为月份 其中 data.id 如“1111”