当您的模型包含具有未知的任意键的对象集合时,查询就没那么有趣了。考虑更改模型以具有已知键并将未知数存储为属性值。例如,改变properties
到一个项目数组:
{
id: "xxxxxx",
properties: [
{
name: "a_prop",
type: "names",
value: "John",
},
{
name: "b_prop",
type: "score",
value: 5.5,
},
{
name: "c_prop",
type: "names",
value: "Steve",
}
]
}
Now the 基于数组的查询 https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-array-contains对于具有“名称”类型属性的项目:
SELECT * FROM c
WHERE ARRAY_CONTAINS(c.properties, {"type": "names"}, true)
另请参阅讨论这个问题 https://stackoverflow.com/questions/63451606/querying-complex-nested-object-in-cosmosdb-using-sql-api/63459762#63459762.