如何在ArangoDB中对对象数组中的对象数组进行过滤和排序

xesrikrc  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(207)

嗨,我有我的有效载荷如下:

{
  "Id": "3",
  "List": {
    "Steps": [
      {
        "StepId": "1",
        "stepDesc1": [
          {
            "sortNo": "2",
            "description": "ABC"
          },
          {
            "sortNo": "1",
            "description": "XYZ"
          }
        ],
        "stepDesc2": [
          {
            "sortNo": "2",
            "description": "AAA"
          },
          {
            "sortNo": "1",
            "description": "BBB"
          }
        ]
      },
      {
        "StepId": "2",
        "stepDesc1": [
          {
            "sortNo": "2",
            "description": "CCC"
          },
          {
            "sortNo": "1",
            "description": "DDD"
          }
        ],
        "stepDesc2": [
          {
            "sortNo": "2",
            "description": "EEE"
          },
          {
            "sortNo": "1",
            "description": "FFF"
          }
        ]
      }
    ]
  }
}

我想按Id和StepId筛选,按SortNo排序并返回数据
我已使用以下查询按Id和StepId进行筛选

FOR test IN test_data
FILTER test.Id=='3' 
FILTER '1' IN test.List.Steps[*].StepId
SORT test.List.Steps[*].stepDesc1.sortNo ASC
RETURN test.Steps

但第二个筛选条件不起作用,并返回与Id 3对应的所有步骤。在我的情况下,它应返回o/p以下

{
        "StepId": "1",
        "stepDesc1": [
          {
            "sortNo": "2",
            "description": "ABC"
          },
          {
            "sortNo": "1",
            "description": "XYZ"
          }
        ],
        "stepDesc2": [
          {
            "sortNo": "2",
            "description": "AAA"
          },
          {
            "sortNo": "1",
            "description": "BBB"
          }
        ]
      }

有谁能帮我解决问题吗

xurqigkl

xurqigkl1#

我相信你正在寻找的是这样的东西。因为你应用的第二个过滤器是真的1确实在数组中,但AQL并没有排除2。它只是说1必须存在。如果你循环嵌套数组-那么你可以使用==。希望这能有所帮助。

FOR test IN test_data
   FILTER test.Id == '3' 
    FOR step IN test.List.Steps
        FILTER step.StepId == '1' 
        SORT step[*].stepDesc1.sortNo ASC

RETURN step

相关问题