Reputation: 31
Here is the problem I am facing:
I am using arangob 3.7 and arangojs driver.
I have following collections:
collection A { _key, data }
collection B { _key, aDataList[A._key] }
I have tried the following
FOR bdoc IN B
FILTER bdoc._key == "some_key"
FOR adoc IN A
FILTER adoc._key IN bdoc.aDataList[*]
RETURN MERGE(bdoc, adoc)
This query returns the objects which falls in to the criteria specified.
But the problem I am facing is the bdoc.aDataList[] order is not same as the one in the actual B document collection. Lets say here is the sample list:
bdoc.aDataList[ 1, 2, 3 ]
How it need to be updated?
bdoc.aDataList[
{
"_key" : 1,
"data" : "somedata"
},
{
"_key" : 2,
"data" : "somedata"
},
{
"_key" : 3,
"data" : "somedata"
}
]
How to properly replace the aDataList[A.Key] with aDataList[A] values using a single aql query?
Any help would be appreciated
Upvotes: 1
Views: 137
Reputation: 31
I have found an answer :)
FOR bDoc IN B
FILTER bDoc.key == “somekey”
LET finalData = ( FOR bDocItem IN bDoc.aDataList
FOR aDoc IN A
FILTER bDocItem[“_key”] == aDoc._key
RETURN aDoc)
RETURN { "_key" : bDoc.key, aDataList: finalData }
Instead of traversing keys of A , I traverse through the array. Thus order is preserved
Upvotes: 2