【问题标题】:AQL nested array valuesAQL 嵌套数组值
【发布时间】:2017-03-22 04:29:41
【问题描述】:

我对 ArangoDB 和 AQL 还很陌生,我的问题与嵌套数组值有关。我不知道是否有办法做到这一点(或者即使我的查询写得很有效)

为了简短起见,我有 2 个系列。一种用于“医师”,一种用于“适应症”。每次我的患者去看医生咨询时,他/她的症状列表都会记录在适应症集合中。但是,之前的诊断可能是由另一位医生做出的。在这种情况下,我的 AQL 语法如下所示:

FOR p in Patients
FILTER p._key=="cad010117"
RETURN {
   "name" : CONCAT(p.pfname, " ", p.plastname),
   "consultations" : (
       FOR i in Indications
       FILTER i.pat_id == p._key
          FOR d in Physicians
          FILTER i.ind_consul_doc == d._key

          RETURN {
              "Doctor" : CONCAT(d.dtitle, " ", d.dfirstname, " ", d.dlastname),
              "Consult Date" : i.ind_consul_dt,
              "Symptoms" : i.symptoms[*],
              "Past Diagnoses" : i.diagnosis[* RETURN {
                      "Condition" : CURRENT.diag, 
                      "Diagnosed on" : CURRENT.diag_dt, 
                      "Diagnosed by" : CURRENT.diag_doc
                  }
              ]
          }
   )

我的对应结果:

[
  {
    "name": "Alfred Jeffries",
    "consultations": [
      {
        "Doctor": "Dr Anthony Garcia",
        "Consult Date": "22nd Jun 2016",
        "Symptoms": [
          {
            "type": "hyperpyrexia",
            "details": "Temperature: 101",
            "duration": "3d"
          },
          {
            "type": "anxiety",
            "details": "Severe",
            "duration": "1w"
          },
          {
            "type": "mania",
            "details": "Moderate",
            "duration": "1w"
          },
          {
            "type": "diaphoresis",
            "details": "Increased sweating during the day only",
            "duration": "3d"
          }
        ],
        "Past Diagnoses": [
          {
            "Condition": "Bipolar Disorder",
            "Diagnosed on": "6th Jul 2016",
            "Diagnosed by": "dc666555"
          }
        ]
      }
    ]

我的问题是,对于返回的 Past Diagnoses 数组,diag_doc 字段是我的“Indications”集合中的诊断数组中的一个值,对应于“Physicians”中的 _key 值做出诊断的医生的集合。使用 AQL 返回 diag_doc 的完整详细信息的最佳方式是什么? 提前谢谢你。

PS:我使用的是 ArangoDB 3.1.12

【问题讨论】:

    标签: arrays arangodb aql


    【解决方案1】:

    您可以使用子查询从Physicians 集合中检索数据:

    "Past Diagnoses": (FOR d IN i.diagnosis RETURN 
      {
        "Condition" : d.diag, 
        "Diagnosed on" : d.diag_dt,
        "Diagnosed by" : FIRST(FOR doc IN Physicians FILTER doc._key == d.diag_doc RETURN doc)
      }
    )
    

    【讨论】:

    • 非常感谢!像魅力一样工作:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 2023-01-28
    • 2020-10-06
    相关资源
    最近更新 更多