5

It seems like the ARRAY_CONTAINS function on nested documents never matches any document.

For example, trying the following simple query with the Azure DocumentDB Query Playground would return no result, even if some nested documents should match this query.

SELECT *
FROM food
WHERE ARRAY_CONTAINS(food.tags.name, "blueberries")

This past question on Stack Overflow also infered that this kind of nested query is valid.

Thank you

1 Answer 1

6

The first argument to ARRAY_CONTAINS must be an array. For example, in this case food.tags is valid as an argument, but food.tags.name is not.

Both the following DocumentDB queries are valid and might be what you're looking for:

SELECT food
FROM food
JOIN tag IN food.tags
WHERE tag.name = "blueberries"

Or

SELECT food
FROM food
WHERE ARRAY_CONTAINS(food.tags, { name: "blueberries" })
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you Aravind, this is what I was looking for :)
Maybe it's worth updating your previous answer stackoverflow.com/questions/31022740/… since it is using the ARRAY_CONTAINS function without an array as the first parameter. I do not have enough reputation to comment it directly.
Thanks - I've fixed the previous answer

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.