0
votes

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

I have the following document in both collections ->

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

This aql query is working fine if {"abc" : false} in collection2 ->

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

2

2 Answers

0
votes

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.

0
votes

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

for collection 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 ->

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