简体   繁体   English

我如何使用单个 aql 查询更新多个集合中的单个或多个文档

[英]how can i can i do update single or multiple document in multiple collection with single aql query

I have two collections with the name "collection1" and "collection2" in database I had created 1 view with name "myview" for search document in both collection我在数据库中有两个名为“collection1”和“collection2”的 collections 我为两个集合中的搜索文档创建了一个名为“myview”的视图

I have the following document in both collections ->我在 collections 中都有以下文档->

{
    "name": "Mac",
    "age": 23,
    "contry":"India",
    "abc":true
  } 

This aql query is working fine if {"abc": false} in collection2 ->如果 {"abc": false} 在 collection2 -> 中,此 aql 查询工作正常

FOR doc IN myview search doc.abc == true update doc with {"alive":true} in collection1 LET updated = OLD RETURN updated

but in my case, this condition is (abc == true) true in both the collection so how can I do update single or multiple documents in multiple collection with single aql query但在我的情况下,这个条件在两个集合中都是 (abc == true) true 所以我如何使用单个 aql 查询更新多个集合中的单个或多个文档

Not sure to understand what you want, but would this query fix your issue?不确定你想要什么,但这个查询能解决你的问题吗?

FOR doc IN myview 
    SEARCH doc.abc == true 
    UPDATE doc WITH {"alive":true} IN collection1 OPTIONS { ignoreErrors: true }
    UPDATE doc with {"alive":true} IN collection2 OPTIONS { ignoreErrors: true }
    LET updated = OLD 
    RETURN updated

OPTIONS { ignoreErrors: true } will make the query pass even if the document is not in the collection. OPTIONS { ignoreErrors: true }即使文档不在集合中,也会使查询通过。

The query given by darkheir is working if we can do some changes like use of update operation for one by one for both collections like this如果我们可以像这样对collections进行一些更改,例如对两个 collections 进行一些更改,例如使用更新操作

for collection 1 ->对于集合 1 ->

 FOR doc IN myview 
        SEARCH doc.abc == true 
        UPDATE doc WITH {"alive":true} IN collection1 OPTIONS { ignoreErrors: true }
        LET updated = OLD 
        RETURN updated

and for Collection 2 ->对于集合 2 ->

FOR doc IN myview 
    SEARCH doc.abc == true 
    UPDATE doc WITH {"alive":true} IN collection2 OPTIONS { ignoreErrors: true }
    LET updated = OLD 
    RETURN updated

how to query for both collection in single aql query如何在单个 aql 查询中查询两个集合

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

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