繁体   English   中英

arangodb AQL如何修改嵌套数组中对象的值?

[英]arangodb AQL How to modify the value of the object in a nested array?

我有这样组织的文件:

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

我在修改“电影”的价值时遇到了问题。 你能帮助我,如何用AQL修改价值?

谢谢!

以下查询应该这样做。 我把解释作为注释放在查询中。 我的示例假定文档存在于名为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

暂无
暂无

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

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