nosql - 过滤嵌套数组项 CosmosDb
问题描述
是否可以在 CosmosDb 中过滤数组项?例如,我只需要客户信息和第一只宠物(在数组中)
当前结果:
[
{
"CustomerId": "100",
"name": "John",
"lastName": "Doe",
"pets": [
{
"id": "pet01",
"CustomerId": "100",
"name": "1st pet"
},
{
"id": "pet02",
"CustomerId": "100",
"name": "2nd pet"
}
]
}
]
预期的:
[
{
"CustomerId": "100",
"name": "John",
"lastName": "Doe",
"pets": [
{
"id": "pet01",
"CustomerId": "100",
"name": "1st pet"
}
]
}
]
解决方案
您可以使用ARRAY_SLICE函数。
SQL:
SELECT c.CustomerId,c.name,c.lastName,ARRAY_SLICE(c.pets,0,1) as pets
FROM c
结果:
[
{
"CustomerId": "100",
"name": "John",
"lastName": "Doe",
"pets": [
{
"id": "pet01",
"CustomerId": "100",
"name": "1st pet"
}
]
}
]
推荐阅读
- java - 在 TextField 中乘以 2 位数字 - Java FX
- r - 将数字分配给组内一年中的月份
- c# - 条件中的游戏任务 C#
- javascript - TINYMCE - 将我想要的任何字体放入文本框中?可能的 ?
- maps - HERE 地图:无法从标记组边界设置 ViewBounds
- reactjs - Webpack-dev-server 如何删除 React 应用程序的默认路由?
- android - 自动完成 Place Api Android
- c++ - 防止签名仅因左值/右值语义不同的函数的代码重复
- php - 如何在 Lumen5.7 中记录数据库查询?
- c# - 在C#中将整数与分数相乘并舍入为整数