couchbase - 如何从兄弟数组中选择字段?

标签 couchbase n1ql

我想从具有 FieldName=Field4 的元素中选择值 ('Value'),其中值 ('Value') 从具有 FieldName=Field2 的元素中为空。

{
    "FormName":"Form1",
    "Id": "ID1",
    "Module":{
       "ModuleType":"Form",
       "Layout":"Vertical",
       "ControlList":[
          {
             "ControlType":"Widget",
             "Layout":"Vertical",
             "FieldList":[
                {
                   "FieldType":"TextBox",
                   "FieldName":"Field1",
                   "Value":"field1"
                },
                {
                   "FieldType":"TextBox",
                   "FieldName":"Field2",
                   "Value":null
                },
                {
                   "FieldType":"TextBox",
                   "FieldName":"Field1",
                   "Value":"field3"
                }
             ]
          },
          {
             "ControlType":"Widget",
             "Layout":"Vertical",
             "FieldList":[
                {
                   "row":[
                      {
                         "FieldType":"TextBox",
                         "FieldName":"Field3",
                         "Value":"field3"
                      },
                      {
                         "FieldType":"TextBox",
                         "FieldName":"Field4",
                         "Value":"field4"
                      }
                   ]
                }
             ]
          }
       ]
    }
 }
我了解如何获得正确的数据集:
select
 form.Id
from
 `test` as form
where
 any cl in form.Module.ControlList satisfies 
   any fl in cl.FieldList satisfies fl.FieldName = 'Field2' AND fl.`Value` is null
   end 
 end;
...返回:
[
  {
    "Id": "ID1"
  }
]
但是我的 select 语句应该如何得到这个:
[
  {
    "Value": "field4"
  }
]

最佳答案

使用 ARRAY construct

SELECT
 ARRAY_FLATTEN((ARRAY (ARRAY (ARRAY {r.`Value`}
               FOR r IN f.`row`
               WHEN r.FieldName = "Field4"
               END)
        FOR f IN c.FieldList
        END)
 FOR c IN t.Module.ControlList
 END),3)[0].*
FROM `test` AS t
WHERE (ANY cl IN t.Module.ControlList
       SATISFIES (ANY fl IN cl.FieldList
                  SATISFIES fl.FieldName = 'Field2' AND fl.`Value` IS NULL
                  END)
       END);

关于couchbase - 如何从兄弟数组中选择字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64433414/

相关文章:

java - Couchbase RX 客户端 - 合并多个可观察量与平面图

couchbase - 获取一组 key ?

javascript - Couchbase 部分更新未按预期工作

java - Couchbase Java SDK : N1QL queries that include document id

Couchbase 4010错误

nosql - 有什么更好/更快的复杂 couchbase ID 或内联文档类型 ="my_document_type"

加载正确的 JAR 时出现 java.lang.NoSuchMethodError 异常

couchbase - N1QL:Couchbase:如何使用混合类型的 concat 函数

java - 从 Couchbase 存储桶中获取所有文件

json - N1QL - 在 CouchBase 中查询多级嵌套的 JSON 数据