0

I have something similar to the following json structure and I need to search for an specific filename in the Azure CosmosDB data explorer (no matter the position), I have been trying differents ways and also using CROSS APPLY FLATTEN but i cannot get it

{
"entityId": "f07256a5-0e60-412a-bcc9-2e1aa66b69f5",
"array1": [
    {
        
        "array2": [
            {
                "fileName": "filename1.pdf",
            },
            {
                "fileName": "filename2.pdf",
            }
        ]
    }
]

}

Any ideas? thanks

1
  • 1
    Looks like a few other questions are similar and answer this question, such as this one and this one Commented Feb 9, 2023 at 14:01

2 Answers 2

3

You need something like below,

SELECT 
    c.fileName  
FROM d
JOIN f IN d.array1
JOIN c IN f.array2
WHERE c.fileName = "filename1.pdf"
Sign up to request clarification or add additional context in comments.

Comments

3

This one works for me:

SELECT c.entityId
FROM c
JOIN one IN c.array1
JOIN two IN one.array2
WHERE two.fileName = 'filename1.pdf'

It uses self-joins to create an object for each filename and then filters from those which has the right filename.

Comments

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.