2017-03-15 53 views
0

我的項目後端是arangodb。我有兩個名爲「test」和「demo」的集合。我需要從這兩個表中獲取數據。我的數據是這樣的:如何從arangodb中的兩個集合中獲取數據

測試

[ 
    { 
    "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的新手。任何建議都將非常可觀。

回答

1

你可以用joinssubqueries來做到這一點。

與子查詢的一種解決方案是這樣的:

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

@clientbind 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" 
     } 
    ] 
    } 
] 
+0

謝謝您的答覆。在這個查詢中,我得到了一個錯誤綁定參數:[「client」]未定義。 – Khushi

+0

您必須定義參數'client'。在WebUi中,您可以在頁面「查詢」的右側看到綁定參數。 – mpv1989

相關問題