如何在arangodb中从两个集合中获取数据

i2loujxw  于 2022-12-09  发布在  Go
关注(0)|答案(3)|浏览(138)

我的项目后端是arangodb。我有两个集合名为“test”和“demo”。我需要从这两个表中获取数据。我的数据如下:
试验,测验

[
  {
    "firstName": "abc",
    "lastName": "pqr",
    "company": "abc Industries",
    "id": "1234"
  },
  {
    "firstName": "xyz",
    "lastName": "qwe",
    "company": "xyz Industries",
    "id": "5678"
  }
]

演示

[
  {
    "clientId": "1234",
    "subject": "test",
    "message": "testing",
    "priority": "High",
    "status": "closed",
    "id": "111111"
  },
  {
    "clientId": "1234", 
    "subject": "hiii",
    "message": "demo",
    "priority": "High",
    "status": "closed",
    "id": "222222"
  },
]

在这个id的测试是相同的clientid的演示。我需要选择数据从表中的数据是客户端“1234”。我怎样才能实现这使用AQL(arango查询语言)。我是新的arango。任何建议将是非常宝贵的。

moiiocjp

moiiocjp1#

您可以使用连接或子查询来执行此操作。
包含子查询的解决方案如下所示:

FOR t IN test
  FILTER t.id == @client
  RETURN { 
    test: t,
    demo: (FOR d IN demo
             FILTER d.clientId == @client
             RETURN d)
  }

@client是一个bind parameter,其中包含您的值1234
其结果是:

[
  {
    "test": {
      "_key": "140306",
      "_id": "test/140306",
      "_rev": "_Urbgapq---",
      "company": "abc Industries",
      "firstName": "abc",
      "id": "1234",
      "lastName": "pqr"
    },
    "demo": [
      {
        "_key": "140233",
        "_id": "demo/140233",
        "_rev": "_UrbfyAm---",
        "clientId": "1234",
        "id": "222222",
        "message": "demo",
        "priority": "High",
        "status": "closed",
        "subject": "hiii"
      },
      {
        "_key": "140200",
        "_id": "demo/140200",
        "_rev": "_UrbfjfG---",
        "clientId": "1234",
        "id": "111111",
        "message": "testing",
        "priority": "High",
        "status": "closed",
        "subject": "test"
      }
    ]
  }
]
z9zf31ra

z9zf31ra2#

For t in test
for d in demo 
filter t.id == d.clientId
filter t.id == @client
return {t,d}
guicsvcw

guicsvcw3#

FOR collection IN [test,demo]
FOR x IN collection
RETURN x

相关问题