简体   繁体   English

如何使用aql在arango中将值附加到map [string] [] string

[英]how to append a value to map[string][]string in arango using aql

how to append a value to array of string using aql query 如何使用aql查询将值附加到字符串数组

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

this is my arango document: 这是我的arango文件:

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

i tried with above query but its overriding existing value but i need something like 我尝试了上述查询,但它覆盖了现有的价值,但我需要类似的东西

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

below is my excepted output for arango document 以下是我对arango文档的例外输出

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

this is my excepted output i just need to append value test to june 2018 key with existing value can someone help me on this please this should be done within aql query 这是我的例外输出,我只需要将值测试附加到具有现有值的2018年6月密钥上,有人可以帮我解决这个问题,这应该在aql查询中完成

To add to your June2018 array, you can use the push function: 要添加到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 } 

that returns: 返回:

[
  {
    "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": ""
    }
  }
]

where you can see that the expected change has taken place. 您可以在其中看到预期的更改。

Note that I changed the column from 'june 2018' to 'june2018', which allowed me to remove all the quotation marks and make the query much cleaner to read (and write). 请注意,我将列从“ june 2018”更改为“ june2018”,这使我可以删除所有引号,并使查询更易于读取(和写入)。 In general, I do not like putting spaces or other special characters in column names as they serve no real purpose beyond forcing me put quotation marks all over the place. 通常,我不喜欢在列名中放置空格或其他特殊字符,因为它们实际上并没有真正的目的,只是迫使我在所有地方都使用引号引起来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM