Once you modify a collection, you cannot make further modifications to the
same collection in the same query. However, you can update a different
collection using the results from the first insert (such as using NEW._key
to update/insert/remove a record in another collection).
For instance, this fails (two inserts into the same collection):
INSERT { value: 'baz' }
INTO a
LET an = NEW
INSERT { value: 'boo' }
INTO a
LET bn = NEW
RETURN { an, bn }
Returns:
ERROR: Query: AQL: access after data-modification by collection 'a'
(while optimizing ast)
But this works just fine (results from insert into "a" are then inserted
into "b"):
INSERT { value1: 'foo' }
INTO a
LET an = NEW
INSERT MERGE(NEW, { value2: 'bar' })
INTO b
LET bn = NEW
RETURN { an, bn }
RETURNS:
[{
"an": { "_id": "a/123", "_key": "123", "_rev": "_eA7tofW---", "value1":
"foo" },
"bn": { "_id": "b/123", "_key": "123", "_rev": "_eA7tofW--_", "value1":
"foo", "value2": "bar" }
}]
On Tuesday, April 5, 2022 at 9:24:23 AM UTC-7 [email protected] wrote:
> Hi,
>
> I am trying to figure out if it is possible to conditionally, based on
> FILTER, INSERT a result into a collection or if the FILTER didnt pass, do a
> REMOVE on the same collection.
>
> Is this possible?
>
--
You received this message because you are subscribed to the Google Groups
"ArangoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/arangodb/28d268f6-fbe7-4b19-9824-a427bebf9c79n%40googlegroups.com.