【问题标题】:how can i can i do update single or multiple document in multiple collection with single aql query我如何使用单个 aql 查询更新多个集合中的单个或多个文档
【发布时间】:2019-11-12 14:58:44
【问题描述】:

我在数据库中有两个名为“collection1”和“collection2”的集合 我为两个集合中的搜索文档创建了 1 个名为“myview”的视图

我在两个集合中都有以下文档 ->

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

如果 {"abc" : false} 在 collection2 中,此 aql 查询工作正常 ->

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

但在我的情况下,这个条件在两个集合中都是 (abc == true) true 那么如何使用单个 aql 查询更新多个集合中的单个或多个文档

【问题讨论】:

    标签: arangodb


    【解决方案1】:

    不确定你想要什么,但是这个查询能解决你的问题吗?

    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 } 将使查询通过,即使文档不在集合中。

    【讨论】:

    • 这不起作用并抛出错误 -> Query: Index out of bounds (while executing) (exception location: /work/ArangoDB/arangod/RestHandler/RestCursorHandler.cpp:283). Please report this error to arangodb.com
    • 您好,darkheir 感谢您的回复。但是,我想使用单个 aql 查询在两个集合中更新
    【解决方案2】:

    darkheir 给出的查询是否有效,如果我们可以做一些改变,比如对这样的两个集合一个一个地使用更新操作

    对于集合 1 ->

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

    对于集合 2 ->

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

    如何在单个 aql 查询中同时查询两个集合

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      相关资源
      最近更新 更多