Nil Pun
Nil Pun

Reputation: 17383

Cosmos Container SQL API Query

I've a document structure below (simplified):

 {
"id": "2345",
"camp{
    "id": 999
    "code": "C1244
    "offers": [
        {
            "status": "active",
            "description": "Commence Loyalty At Year 6"
        },
        {
            "status": "inactive"
            "description": "abcd test
        }
    }
}

Where I would like to filter the offers where status is active. Can someone help me with what the query may look like for this?

Upvotes: 0

Views: 82

Answers (1)

Steve Johnson
Steve Johnson

Reputation: 8690

Please try something like this sql:

SELECT  c.camp.id,c.camp.code,d AS offer FROM c join d in c.camp.offers where d.status = 'active'

Here is the result:

[
    {
        "id": 999,
        "code": "C1244",
        "offer": {
            "status": "active",
            "description": "Commence Loyalty At Year 6"
        }
    }
]

Hope this can help you:).

Upvotes: 1

Related Questions