Example:
xquery version "1.0-ml";
for $Schema_Student in collection ("Student"), $Schema_Staff in collection ("Staff")
where ($Schema_Student/Student/Pincode = $Schema_Staff/Schema_Staff/Pincode)
return document-uri($Staff)
Output will be document URIs from "Staff" Collection.
Data details: If I have 10 document-uri with the Pincode "560049" in the "Student" collection and 10 document-uri with the Pincode "560049" in the "Staff" collection:
My expected output is 10 document-uri, but the output of this query is returning 100 document-uri.
This query does a lot of things internally by joining
If I have 10 document-uri of "Student" and 10 of "Staff" collections,
The result of joining will give you 10*10 = 100 document URIs, which is an unnecessary join.
Do we have an optimized solution for joining two collections?
Note: Condition fields don't have the path range index.
Any suggestions?
I tried the CTS query, but it needs to have a path range index. But for my requirement, fields can be without path range index.
Try the below code (which will result in lesser loop execution).
One disadvantage in the above approach is
collection("Staff")/Schema_Staff/Pincodeis executed once for every document undercollection("Student"). I would prefer the following: