DocumentDb - query at sub-document and root level

Notify me | Edit | Delete | Change type Question You cannot vote on your own post 0 Hello!

Suppose I have documenters as follows:

{
  id: 123,
  tags: [ { name: "something" } ]
}

and I want to request all documents containing a tag with name = "search" OR have id = 9000. I tested on the playground ( https://www.documentdb.com/sql/demo ) something like:

SELECT food.id, food.description, food.tags
FROM food
JOIN tag IN food.tags
WHERE food.id = "09052" or tag.name="blueberries"

but then I get a bunch of duplicate entries, each document from the food is the number of tags in this document.

How can I get great results when filtering by nested collection and root properties?

+3
source share
1 answer

ARRAY_CONTAINS , . . https://msdn.microsoft.com/library/azure/dn782250.aspx#bk_array_functions, :

SELECT food.id, food.description, food.tags
FROM food
WHERE food.id = "09052" or ARRAY_CONTAINS(food.tags, { "name": "blueberries" })

Query here.

, , . - , , "" .

+4

Source: https://habr.com/ru/post/1661229/


All Articles