1

I have a Cosmos DB database with documents that have the following form:

{
  "Id": "1",
  "Price": 200,
  "Properties": [
    {
        "Name": "Name1",
        "Type": "Type1",            
    },
    {
        "Name": "Name2",
        "Type": "Type2",            
    }
  ]
},
{
  "Id": "2",
  "Price": 500,
  "Properties": [
    {
        "Name": "Name1",
        "Type": "Type1",            
    },
    {
        "Name": "Name2",
        "Type": "Type3",            
    }
  ]
},
{
  "Id": "3",
  "Price": 400,
  "Properties": [
    {
        "Name": "Name1",
        "Type": "Type2",            
    }
  ]
}

I would like to create a query that returns documents that satisfy multiple properties. E.g. I would like to retrieve the documents that have both properties of Type1 and Type2. The result should give me only the document with Id = 1.

1 Answer 1

3
SELECT c.Id
FROM c
WHERE ARRAY_CONTAINS(c.Properties, {'Type': 'Type1' }, true)
AND ARRAY_CONTAINS(c.Properties, {'Type': 'Type2' }, true)
Sign up to request clarification or add additional context in comments.

5 Comments

What does the third argument (true) do? I cannot find any documentation on this argument.
The third boolean parameter is for enabling or disabling partial matching (ie, this property of the object matches but the rest of the object doesn't have to). It doesn't appear to be well documented
See this question stackoverflow.com/questions/46794691/… which was answered by someone directly from the Cosmos team
Ah ok, I missed that one. It would be nice if this was documented. I tried to add a comment to the documentation page, but that did not work (just says "error")
We'll get this added to the documentation asap.

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.