I have read the Azure cosmos document and it currently says that it doesn't allow to JOIN 2 different collection in the same DB. I need help on achieving the below scenario. Below is the documents in Cosmos DB. I am using SQL API for the same.
All the below documents are in same collection. 'id' is the partition key.
Document 1:
{
"id": "12343920",
"status": "1",
"code": "111116"
}
Document 2:
{
"id": "12343921",
"status": "8",
"code": "111117"
}
Document 3: [ Different from other documents ]
{
"id": "active",
"Part": [
{
"Name": "ABC",
"Status": [
"1",
"2",
"3"
]
},
{
"Name": "DEF",
"Status": [
"6",
"2",
"8"
]
}
],
}
I have a stored procedure where the API comes with 3 parameters,
- id
- code
- Name
I need to find the status from Document 3 for the corresponding Name [ from API ] and then need to apply IN clause in the other documents to find the matching response.
I tried few queries as below.
I tried to get the array of string for the status from document 3:
SELECT Value t.Status
from f
JOIN t in f.Part
where t.Name=@Name
This query works in SQL editor[ if I substitute @Name with ABC] but shows no document when executing in stored procedure.
Other code :
SELECT n.id,n.code,n.Status
FROM order n
where n.Code=@Code
and n.id=@id and n.Status IN (
SELECT ARRAY(
SELECT Part.Status
FROM Part
in order.Part
WHERE Part.Name=@Name)
FROM orders WHERE orders.id='active')
It says error near SELECT statement.
Result what I am expecting is as below which matches the parameters from the API.
{
"id": "12343920",
"status": "1",
"code": "111116"
}