Return 数组中特定对象的内容 — CosmosDB
Return the content of a specific object in an array — CosmosDB
这是问题
的跟进
我当前的查询
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 ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
我的查询输出
[
{
"EndDeviceEventDetail": [
{
"name": "Spontaneous",
"value": "true"
},
{
"name": "DetectionActive",
"value": "true"
},
{
"name": "RCDSwitchReleased",
"value": "true"
}
]
}
]
问题
如何更改我的查询,以便我 select 仅 包含 "name" [=33= 的数组的 "value" ] ?
背后的想法是过滤一个数组条目上的查询,并获得另一个数组条目的 "value" 作为输出。从这里阅读,应该使用 UDF(在这种情况下不是最好的)和 JOIN。
第一次尝试
SELECT t.value FROM c JOIN t in c.EventType.EndDeviceEventDetail
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 ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
收到错误请求 (400) 错误
你的想法和方向绝对正确,我简化测试了你的sql。
SELECT detail.value FROM c
join detail in c.EventType.EndDeviceEventDetail
WHERE c.EventType.EndDeviceEventType.eventOrAction = '93'
AND ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
发现错误信息如下:
因为value
是cosmos db sql语法中的保留字,请参考这个案例:Using reserved word field name in DocumentDB
您可以尝试将 sql 修改为:
SELECT detail["value"] FROM c
这是问题
我当前的查询
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 ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
我的查询输出
[
{
"EndDeviceEventDetail": [
{
"name": "Spontaneous",
"value": "true"
},
{
"name": "DetectionActive",
"value": "true"
},
{
"name": "RCDSwitchReleased",
"value": "true"
}
]
}
]
问题
如何更改我的查询,以便我 select 仅 包含 "name" [=33= 的数组的 "value" ] ? 背后的想法是过滤一个数组条目上的查询,并获得另一个数组条目的 "value" 作为输出。从这里阅读,应该使用 UDF(在这种情况下不是最好的)和 JOIN。
第一次尝试
SELECT t.value FROM c JOIN t in c.EventType.EndDeviceEventDetail
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 ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
收到错误请求 (400) 错误
你的想法和方向绝对正确,我简化测试了你的sql。
SELECT detail.value FROM c
join detail in c.EventType.EndDeviceEventDetail
WHERE c.EventType.EndDeviceEventType.eventOrAction = '93'
AND ARRAY_CONTAINS(c.EventType.EndDeviceEventDetail,{"name":
"RCDSwitchReleased","value": "true" })
发现错误信息如下:
因为value
是cosmos db sql语法中的保留字,请参考这个案例:Using reserved word field name in DocumentDB
您可以尝试将 sql 修改为:
SELECT detail["value"] FROM c