簡體   English   中英

我如何使用單個 aql 查詢更新多個集合中的單個或多個文檔

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

我在數據庫中有兩個名為“collection1”和“collection2”的 collections 我為兩個集合中的搜索文檔創建了一個名為“myview”的視圖

我在 collections 中都有以下文檔->

{
    "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 查詢更新多個集合中的單個或多個文檔

不確定你想要什么,但這個查詢能解決你的問題嗎?

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 }即使文檔不在集合中,也會使查詢通過。

如果我們可以像這樣對collections進行一些更改,例如對兩個 collections 進行一些更改,例如使用更新操作

對於集合 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 查詢中查詢兩個集合

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM