I query a CosmosDB database using the following query :
SELECT c.EventType.EndDeviceEventDetail FROM c
WHERE (c.EventType.EndDeviceEventType.eventOrAction = '93'
AND c.EventType.EndDeviceEventType.subdomain = '137'
AND c.EventType.EndDeviceEventType.domain = '26'
AND c.EventType.EndDeviceEventType.type = '3')
I get as a response
[
{
"EndDeviceEventDetail": [
{
"name": "Spontaneous",
"value": "true"
},
{
"name": "DetectionActive",
"value": "true"
},
{
"name": "RCDSwitchReleased",
"value": "false"
}
]
},
{
"EndDeviceEventDetail": [
{
"name": "Spontaneous",
"value": "true"
},
{
"name": "DetectionActive",
"value": "true"
},
{
"name": "RCDSwitchReleased",
"value": "true"
}
]
}
]
I would like to get as step further and modify my query so that I get a response only if "RCDSwitchReleased" is true.
I naïvely tried without success :
SELECT c.EventType.EndDeviceEventDetail FROM c
WHERE (c.EventType.EndDeviceEventType.eventOrAction = '93'
AND c.EventType.EndDeviceEventType.subdomain = '137'
AND c.EventType.EndDeviceEventType.domain = '26'
AND c.EventType.EndDeviceEventType.type = '3')
AND c.EventType.EndDeviceEventDetail[2].value = 'true'
but I get a BadRequest (400) error message. Any direction/help to achieve this ?
An issue with
Value
Keyword. Cosmos SQL use Value Keyword in many different ways, this is might be a reason, we can't use value field in select query.I Changed the document with
value1
insteadvalue
then your query is working.Suggestion
If you are applying a filter in the array, Always use Array_Contains. If order of value inside your array
EndDeviceEventDetail
would change, your query will not return the correct result.My query
Query Output