如何使用aql

时间:2019-07-19 11:38:23

标签: arangodb

如何使用aql查询将值附加到字符串数组

{
  "annotation_id": "1234",
  "text": {
    "june 2018": [
      "gain of revenue for this month"
    ]
  },
  "user_id": ""
}

这是我的arango文档:

for doc in annotation_info 
filter doc.annotation_id == '1234' 
update doc with {"text": {"june 2018":["test"]}} in annotation_info

我尝试了上面的查询,但是它覆盖了现有的值,但是我需要类似的东西

{   "annotation_id": "1234",   "text": {
    "june 2018": [
      "gain of revenue for this month",
      "test"
    ]   },   "user_id": "" }

以下是我对arango文档的例外输出

{
  "annotation_id": "1234",
  "text": {
    "june 2018": [
      "gain of revenue for this month",
      "test"
    ]
  },
  "user_id": ""
}

这是我的例外输出,我只需要将价值测试附加到具有现有价值的2018年6月密钥上,有人可以对此进行帮助吗? 这应该在aql查询中完成

1 个答案:

答案 0 :(得分:0)

要添加到June2018数组中,可以使用push函数:

for doc in annotation_info 
filter doc.annotation_id == '1234' 
update doc with {text: {june2018 :push(doc.text.june2018, 'test')}} in annotation_info
RETURN { before: OLD, after: NEW } 

返回:

[
  {
    "before": {
      "_key": "45740",
      "_id": "test5/45740",
      "_rev": "_Z-plp5S--_",
      "annotation_id": "1234",
      "text": {
        "june2018": [
          "gain of revenue for this month"
        ]
      },
      "user_id": ""
    },
    "after": {
      "_key": "45740",
      "_id": "test5/45740",
      "_rev": "_Z-pl0cu--_",
      "annotation_id": "1234",
      "text": {
        "june2018": [
          "gain of revenue for this month",
          "test"
        ]
      },
      "user_id": ""
    }
  }
]

您可以在其中看到预期的更改。

请注意,我将列从“ june 2018”更改为“ june2018”,这使我可以删除所有引号,并使查询更易于读取(和写入)。通常,我不喜欢在列名中放置空格或其他特殊字符,因为它们除了迫使我在所有地方都使用引号之外没有实际目的。

相关问题