【问题标题】:how to append a value to map[string][]string in arango using aql如何使用 aql 在 arango 中将值附加到 map[string][]string
【发布时间】:2019-07-20 01:11:16
【问题描述】:

如何使用 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": ""
}

这是我的例外输出,我只需要将 value test 附加到 2018 年 6 月具有现有值的键,有人可以帮助我吗? 这应该在 aql 查询中完成

【问题讨论】:

  • @stackoverflow 我们看不到您的预期输出

标签: arangodb


【解决方案1】:

要添加到您的 June2018 数组,您可以使用推送功能:

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”,这使我可以删除所有引号并使查询更易于阅读(和编写)。一般来说,我不喜欢在列名中添加空格或其他特殊字符,因为它们除了强迫我在所有地方都加上引号之外没有任何实际用途。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 2020-07-22
    • 1970-01-01
    • 1970-01-01
    • 2018-08-02
    相关资源
    最近更新 更多