如何在 CosmosDB 中查询子列表以获得所需的输出

How to Query Sublist in CosmosDB to desired output

{
  "Name": "Sam",
  "Car": [
    {
      "Brand": "BMW",
      "Category": "HunchBack",
      "Type": "Gas"
    },
    {
      "Brand": "Tesla",
      "Category": "Sedan",
      "Type": "Electric"
    }
  ]
}

我想用 Cosmos Sqlquery 查询 BRAND 上的子列表 CAR,它只会 return 那些匹配的文档标准。

Select * from c JOIN t IN c.Car
where t.BRAND = 'Tesla'

我试过了,但它只部分起作用,因为它也 return 子列表 BMW

但预期输出是

{
  "Name": "Sam",
  "Car": [
    {
      "Brand": "Tesla",
      "Category": "Sedan",
      "Type": "Electric"
    }
  ]
}

试试看?

Select distinct c.Name,ARRAY(SELECT n.Brand,n.Category,n.Type FROM n IN c.Car where n.Brand = 'benci') as Car from c JOIN t in c.Car where t.Brand='benci'