1

is there a way of producing following query?

{ 
  "user": { 
    "name": "john", 
    "tags": ["one", "two", "three"] 
  } 
}

now given an array of tags

["one","two","five"]

I want to select all users (distinct if possible) who have at least one tag in common with incoming tag array.

Community
  • 1
  • 1
Peter Zajic
  • 899
  • 8
  • 17

1 Answers1

2

You have to write a user defined function to do this. For example, I searched for JavaScript array intersection in StackOverflow and found this: Simplest code for array intersection in javascript

You can register this as a UDF in your collection, and then query like:

SELECT * FROM docs WHERE udf.ARRAY_INTERSECTS(docs.tags, ["a", "b", "c"]) != []

Note however that this requires a scan..

Community
  • 1
  • 1
Aravind Krishna R.
  • 7,885
  • 27
  • 37