gpt4 book ai didi

azure - 宇宙数据库 : Find the index of an item in an array

转载 作者:行者123 更新时间:2023-12-02 23:36:21 24 4
gpt4 key购买 nike

我想查找 Cosmos DB 中嵌套数组中所有项目的索引号:

数据:

{
"id":"MyId",
"items" : [
{"id": "Item1"},
{"id" : "Item2"}
]
}

查询:

SELECT f.id, index : ** How to get the index of items ? ** 

FROM root JOIN f IN root["items"]

WHERE (IS_DEFINED(root["items"]) AND (root["id"] = "MyId"))

我想要这样的结果:

[

{"id": "item1", "index": 0},

{"id": "item2", "index" : 1}

]

谢谢

最佳答案

Cosmos SQL API 没有内置支持来实现上述结果。但您可以实现以下建议

  1. 您可以在 User Defined Function 中编写自己的逻辑或者检索数据并按照您在客户端上需要的方式对其进行格式化侧面

  2. 其他方法是将索引包含在数据模型本身中

关于azure - 宇宙数据库 : Find the index of an item in an array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71382609/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com