【问题标题】:arangodb AQL How to modify the value of the object in a nested array?arangodb AQL 如何修改嵌套数组中对象的值?
【发布时间】:2017-10-12 01:39:36
【问题描述】:

我的文档是这样组织的:

{
  "email": "tyler_li@126.com",
  "name": "tyler",
  "address": {
    "street": "Beijing Road",
    "zip": 510000
  },
  "likes": [
    "running",
    {
      "movie": "Star Wars"
    }
  ]
}

我在修改“电影”的值时遇到问题。您能帮我吗,如何使用 AQL 修改值?

谢谢!

【问题讨论】:

    标签: arangodb aql


    【解决方案1】:

    以下查询应该可以。我将解释作为 cmets 放在查询中。我的示例假设文档存在于名为 collection 的集合中:

    FOR doc IN collection
      /* any filter condition to find the document(s) in question.
         you should make sure this uses an index if there is a substantial
         number of documents in the collection */
      FILTER doc.name == 'tyler' 
    
      /* enumerate the old likes and return them as is if they are not
         of type object or do not have a 'movie' attribute. If they are
         objects and have a 'movie' attribute, patch them with a 'movie'
         value of 'whatever' */
      LET newLikes = (
        FOR oldLike IN doc.likes 
          RETURN 
            (TYPENAME(oldLike) == 'object' && HAS(oldLike, 'movie')) ?
                { movie: 'whatever' } :
                oldLike
      ) 
    
      /* finally update the matching document(s) with the new likes */
      UPDATE doc WITH { likes: newLikes } IN collection
    

    【讨论】:

    • 非常感谢您的详细解答。
    猜你喜欢
    • 2020-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多