【问题标题】:Cosmos DB SQL Query for nested objects嵌套对象的 Cosmos DB SQL 查询
【发布时间】:2019-01-25 20:38:17
【问题描述】:

我在 Cosmos DB 中有帐户集合。我尝试了不同的查询,但未能通过等效的 SQL 查询仅获取已选择订阅的帐户。

我试过这个查询但失败了

SELECT     *
FROM account a
JOIN s IN c.subscriptions
WHERE s.id = "e5969a3c-2729-cb3c-a01b-2e62e0473646"

收款记录

[
  {
    "id": "8c549b95-480e-47f9-acd6-13339179399f",
    "odoo_id": "UpdatedDAta",
    "entity_name": "Lakes High School123",
    "entity_type": "family | teacher | school | district",
    "contacts": [
      {
        "name": "Mr. Garcia1",
        "email": "Garcia@junk.com"
      },
      {
        "name": "Mr. Garcia3",
        "email": "Garcia@junk.com"
      }
    ],
    "subscriptions": [
      {
        "id": null,
        "type": "group | profile",
        "group_name": "Year 4",
        "teachers": [
          "Ms Jones"
        ],
        "start_date": "25/7/2018",
        "end_date": "24/7/2019",
        "seats": 4,
        "group_key": "red-limping-pigeon"
      },
      {
        "id": "e5969a3c-2729-cb3c-a01b-2e62e0473646",
        "type": "group | profile",
        "group_name": "Year 4",
        "teachers": [
          "Ms Jones",
          "Waqar"
        ],
        "start_date": "25/7/2018",
        "end_date": "24/7/2021",
        "seats": 4,
        "group_key": "red-limping-pigeon"
      }
    ],
    "_rid": "bjcNANQrW3oGAAAAAAAAAA==",
    "_self": "dbs/bjcNAA==/colls/bjcNANQrW3o=/docs/bjcNANQrW3oGAAAAAAAAAA==/",
    "_etag": "\"01001c87-0000-0000-0000-5b7966850000\"",
    "_attachments": "attachments/",
    "_ts": 1534682757
  }
]

【问题讨论】:

    标签: azure-cosmosdb document-database


    【解决方案1】:

    请使用以下 sql 获取您的文档:

    SELECT * FROM c
    where ARRAY_CONTAINS(c.subscriptions,{"id": "e5969a3c-2729-cb3c-a01b-2e62e0473646"},true)
    

    Array Contains 可以返回一个布尔值,指示数组是否包含指定的值。

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2019-01-21
      • 2021-12-14
      • 2019-04-21
      • 1970-01-01
      • 2018-12-17
      • 2021-12-27
      • 2019-11-20
      • 2021-05-22
      • 2019-09-26
      相关资源
      最近更新 更多