[英]How to remove collection or edge document using for loop in ArangoDB?
I'm using the latest ArangoDB 3.1 on Windows 10. 我正在Windows 10上使用最新的ArangoDB 3.1。
Here I want to remove the collection document and edge document using the for loop. 在这里,我想使用for循环删除收集文档和边文档。 But I'm getting an error like document not found (vName) .
但是我遇到了类似找不到文档(vName)的错误。
vName contains the many collection names . vName包含许多集合名称 。 But I dunno how to use it in for loop .
但是我不知道如何在for循环中使用它。
This is the AQL I am using to remove the documents from the graph: 这是我用来从图中删除文档的AQL:
LET op = (FOR v, e IN 1..1 ANY 'User/588751454' GRAPH 'my_graph'
COLLECT vid = v._id, eid = e._id
RETURN { vid, eid }
)
FOR doc IN op
COLLECT vName = SPLIT(doc.vid,'/')[0],
vid = SPLIT(doc.vid,'/')[1],
eName = SPLIT(doc.eid,'/')[0],
eid = SPLIT(doc.eid,'/')[1]
REMOVE { _key: vid } in vName
Return output im getting from the AQL (Web UI screenshot) 从AQL返回输出即时消息 (Web UI屏幕截图)
vName
is a variable introduced by COLLECT
. vName
是COLLECT
引入的变量。 It is a string with the collection name of a vertex (extracted from vid / v._id). 它是一个具有顶点集合名称的字符串(从vid / v._id中提取)。 You then try to use it in the removal operation
REMOVE { ... } IN vName
. 然后,您尝试
REMOVE { ... } IN vName
中的删除操作REMOVE { ... } IN vName
使用它。
AQL does not support dynamic collection names however, collection names must be known at query compile time: AQL不支持动态集合名称,但是,必须在查询编译时知道集合名称:
Each REMOVE operation is restricted to a single collection, and the collection name must not be dynamic.
每个REMOVE操作都限于一个集合,并且集合名称不得为动态。
Source: https://docs.arangodb.com/3.2/AQL/Operations/Remove.html 资料来源: https : //docs.arangodb.com/3.2/AQL/Operations/Remove.html
So, you either have to hardcode the collection into the query, eg REMOVE { ... } IN User
, or use the special bind parameter syntax for collections, eg REMOVE { ... } IN @@coll
and bind parameters: {"@coll": "User", ...}
. 因此,您必须将集合硬编码到查询中,例如
REMOVE { ... } IN User
,或者对集合使用特殊的绑定参数语法,例如REMOVE { ... } IN @@coll
并绑定参数: {"@coll": "User", ...}
。
This also means that REMOVE
can only delete documents in a single collection. 这也意味着
REMOVE
只能删除单个集合中的文档。
It's possible to workaround the limitation somewhat by using subqueries like this: 通过使用如下子查询,可以在某种程度上解决该限制:
LET x1 = (FOR doc IN User REMOVE aa IN User)
LET x2 = (FOR doc IN relations REMOVE bb IN relations)
RETURN 1
The variables x1 and x2 are syntactically required and receive an empty array as subquery result. 语法上要求变量x1和x2并接收一个空数组作为子查询结果。 The query also requires a
RETURN
statement, even if we don't expect any result. 该查询还需要一个
RETURN
语句,即使我们不希望有任何结果。
Do not attempt to remove from the same collection twice in the same query though, as it would raise a access after data-modification error. 但是,请勿尝试在同一查询中两次从同一集合中删除,因为这将在数据修改错误后引发访问 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.