1

We have a below document structure.

{
"id":"GUID",
    "customer": {
            "contacts": [
                {
                    "type": "MOBILE",
                    "status": "CONFIRMED",
                    "value": "xxxx"
                },
                {
                    "type": "EMAIL",
                    "status": "CONFIRMED",
                    "value": "aaaa"
                }
            ],
            "addresses": [
                {

                    "country": "xxx"
                }
            ]
        }
}

and need to search for customer->contacts where value="aaaa". I tried with below options

1)  SELECT c.id FROM c
    join customer in c.customer
    join contacts in c.customer.contacts
    where contacts.value = "aaaa"

2) SELECT c.id FROM c WHERE c.customer.contacts[0].value= "aaaa"

Getting Syntax error 400 bad request Any help highly appreciated

1 Answer 1

1

Part of your issue is that value cannot be searched as easily as other properties. Here are possible solutions:

SELECT c.id FROM c
join contacts in c.customer.contacts where contacts["value"] = "aaaa"

SELECT c.id FROM c WHERE c.customer.contacts[1]["value"] = "aaaa"

Document DB SQL Api - unable to query json property with name 'value' and its value is integer

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @AlexAIT, your query worked as charm. I was not aware of limitation, JSON property name - 'value'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.