Hello, I am trying to access values within CosmosDB and have hit a roadblock. Any insight is appreciated:
I wish to locate all the nested fields within my JSON document that contain the "state" = "new" and where the "id" length > 4
{ "id": "123" "feedback" : { "Features" : [ { "state":"new" "id": "12345" } ] }
This is what I have tried to do:
Since this is a nested document. My query looks like this:
SELECT c.feedback ARRAY(SELECT Features.state FROM c IN c.Features) AS Features FROM c WHERE length(Features.id) >15
However, the syntax is not correct and I am currently researching and looking for examples for this case
Any help is appreciated
Hello, this is the query you are looking for:
SELECT c.feedback from c join a in c.feedback.Features where a.state = 'new' and length(a.id) > 4
As you can see there is a join on the Features array and then the fields of that array can be queried.
There are also additional options on the ARRAY_CONTAINS which are interesting to look at if you are working with nested objects and nested arrays.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hello, I am trying to access values within CosmosDB and have hit a roadblock. Any insight is appreciated:
I wish to locate all the nested fields within my JSON document that contain the "state" = "new" and where the "id" length > 4
This is what I have tried to do:
Since this is a nested document. My query looks like this:
However, the syntax is not correct and I am currently researching and looking for examples for this case
Any help is appreciated
Hello, this is the query you are looking for:
As you can see there is a join on the Features array and then the fields of that array can be queried.
There are also additional options on the ARRAY_CONTAINS which are interesting to look at if you are working with nested objects and nested arrays.