0

I want to fetch common elements from multiple arrays. The no. of arrays resulted would keep changing depending upon the no. of tags in array a[].

As a first step, my query and result I get is as shown below:

let a=["Men","Women","Accessories"]
let c=(for i in a
       Let d=Concat("Tags/",i)
       return d)

for i in c
   let m=(for y in outbound i TC 
          return y._key)
   return m

and result I get is:

[
  [
    "C1",
    "C5",
    "C7",
    "C3"
  ],
  [
    "C2",
    "C5",
    "C6",
    "C4"
  ],
  [
    "C7",
    "C5",
    "C6"
  ]
]

From this result, I want only common element as a result i.e "C5" (here).

How can I get that?

  • Do you know the number of tags ahead of time? If so you could end your query with something like. `let D= [["C1","C5","C7","C3"],["C2","C5","C6","C4"],["C7","C5","C6"]] return INTERSECTION(D[0],D[1],D[2])` – camba1 Oct 10 '18 at 15:34
  • You don't need to know the number in advance, you can use APPLY() to make this work with a dynamic amount of nested arrays, e.g. `APPLY("INTERSECTION", D)`. See docs: https://docs.arangodb.com/3.3/AQL/Functions/Miscellaneous.html#apply – CodeManX Oct 10 '18 at 15:49

1 Answers1

0

This question has also been asked and answered on github.

The function INTERSECTION() returns the intersection of all specified arrays and APPLY() is used to pass a dynamic amount of nested arrays.

The query

let D = [["C1","C5","C7","C3"],["C2","C5","C6","C4"],["C7","C5","C6"]] 

RETURN APPLY("INTERSECTION", D)

results in:

[
  [
    "C5"
  ]
]