简体   繁体   English

在ArangoDB AQL中,无论集合如何,如何更新每个遍历对象的字段?

[英]In ArangoDB AQL how do I update fields of every traversed object, regardless of collection?

The UPDATE statement requires a collection name. UPDATE语句需要一个集合名称。 In a graph, I want to traverse an edge and update each vertex visited. 在图形中,我想遍历一条边并更新访问的每个顶点。

Something like: FOR v IN 1..50 INBOUND 'pmconfig/6376876' pm_content OPTIONS {uniqueVertices: "global"} [update v.contentsChanged=true] 类似于:FOR v IN 1..50 INBOUND'pmconfig / 6376876'pm_content选项{uniqueVertices:“ global”} [update v.contentsChanged = true]

Since the vertices may be found in different collections, do I have to partition the objects into per-collection lists? 由于顶点可以在不同的集合中找到,我是否必须将对象划分为每个集合列表?

Updating documents using a dynamic (run-time) collection name is not possible. 无法使用动态(运行时)集合名称更新文档。 For example, the following AQL query will not compile: 例如,以下AQL查询将不会编译:

FOR v IN 1..50 INBOUND 'pmconfig/6376876' pm_content
  UPDATE v WITH { contentsChanged : true } IN PARSE_IDENTIFIER(v._id).collection

The reason is that UPDATE and other data modification statements require their collection names to be known at query compile time. 原因是UPDATE和其他数据修改语句要求在查询编译时知道其集合名称。 Using bind parameters will work, of course, but no runtime expressions are allowed. 当然,使用绑定参数将起作用,但不允许运行时表达式。

One workaround is to run the traversal multiple times, each time with a hard-coded collection to update. 一种解决方法是多次运行遍历,每次都使用硬编码集合进行更新。 This still requires knowledge of the collection names in advance. 这仍然需要事先了解集合名称。 There may also be consistency issues if the graph changes in between: 如果图形在以下之间进行更改,则可能还会存在一致性问题:

FOR v IN 1..50 INBOUND 'pmconfig/6376876' pm_content
  FILTER PARSE_IDENTIFIER(v._id).collection == 'vertexCollection1'
  UPDATE v WITH { contentsChanged : true } IN vertexCollection1

FOR v IN 1..50 INBOUND 'pmconfig/6376876' pm_content
  FILTER PARSE_IDENTIFIER(v._id).collection == 'vertexCollection2'
  UPDATE v WITH { contentsChanged : true } IN vertexCollection2

...

Another workaround is to have the traversal already generate the per-collection lists, and issue follow-up queries for each collection. 另一个解决方法是让遍历已经生成每个集合列表,并对每个集合发出后续查询。 For example, the following query should return the keys to update per collection: 例如,以下查询应返回每个集合要更新的键:

FOR v IN 1..50 INBOUND 'pmconfig/6376876' pm_content
  LET parts = PARSE_IDENTIFIER(v._id) 
  COLLECT collection = parts.collection INTO keys = parts. key 
  RETURN { collection, keys }

Example result: 结果示例:

[    
  { 
     "collection" : "vertexCollection1", 
     "keys" : [ 
       "abc" 
     ]    
  },    
  { 
    "collection" : "vertexCollection2", 
    "keys" : [ 
      "xyz", 
      "ddd" 
    ]    
  }  
]

Using the result structure, the follow-up update queries can be constructed easily and the updates be sent. 使用结果结构,可以轻松构造后续更新查询并发送更新。

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

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