簡體   English   中英

在 gremlin 中加入查詢,組導致一對多關系

[英]Join query in gremlin, group results in a one to many relationship

我必須輸入頂點國家和機場的類型,並且每個國家都有與 label “hasAirport”的多個機場的優勢

我正在嘗試一個連接查詢,它將返回與他們擁有的機場分組的國家。

g.V().hasLabel("Country").as("country").out('hasAirport').as("airport").select("country", "airport").by(__.unfold().valueMap(true).fold()).toList()

如果我的圖表中只有一個國家說美國有兩個機場,則查詢結果如下所示。

[   {
    "country": [
      {
        "name": "United States",
        "code": "USA",      "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 1234,
        "label": "Airport",
        "name": "San Francisco International Airport",      "code": "SFO"
      }
    ]   },   {
    "country": [
      {
        "name": "United States",
        "code": "USA",      "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 2345,
        "label": "Airport",
        "name": "Austin Bergstrom International Airport",       "code": "AUS"
      }
    ]   }  ]

有沒有辦法將多個機場聚集在一個數組中,如下所示

[
  {
    "country": [
      {
        "name": "United States",
        "code": "USA",
        "label": "Country",
        "id": 1565,
      }
    ],
    "airport": [
      {
        "id": 1234,
        "label": "Airport",
        "name": "San Francisco International Airport",
        "code": "SFO"
      },
      {
        "id": 2345,
        "label": "Airport",
        "name": "Austin Bergstrom International Airport",
        "code": "AUS"
      }
    ]
  }
 ]

您需要使用project

g.V().hasLabel("Country")
.project("country","airport")
.by(valueMap(true))
.by(out('hasAirport').valueMap(true).fold())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM