Skip to content
Advertisement

Unexpected behavior of ARRAY_SLICE in Cosmos Db SQL API

I have Cosmos DB collection (called sample) containing the following documents:

I am trying to retrieve all the Documents, having messages and the first message has the field "Text"= 'Value1'. In this sample the documents with the ids '1' and '3' would be retrieved. Please notice that the document with id='id2' wouldn’t be retrieved, since the value of the text of the first message is 'Value3'.

The collection as mentioned is called sample and I am running the following Query:

As you can see in the first two images, I retrieve all Documents and every one of them have the field "valueOfText" set to value of the first message, as expected.

Part 1 of the query result enter image description here

Now when I filter the collection (the third image), I retrieve no results at all. enter image description here Is this an expected behavior?

Advertisement

Answer

Following your sql, got same results:

enter image description here

But why you have to use ARRAY_SLICE,it is used to return truncated array.Since your requirement is specific:

trying to retrieve all the Documents, having messages and the first message has the field “Text”= ‘Value1’

Just use sql:

Output:

enter image description here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement