Peter Zajic
Peter Zajic

Reputation: 899

matching array content in azure documentdb

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.

Upvotes: 1

Views: 468

Answers (1)

Aravind Krishna R.
Aravind Krishna R.

Reputation: 8003

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..

Upvotes: 2

Related Questions