0

In this case, the documents look like:

{
 "id" : "1",
 "Properties" : [
  {
   "Name" : "Leonard",
   "Result" : "Pass",
   "Grade" : "A"
  },
  {
   "Name" : "Sheldon",
   "Result" : "Pass",
   "Grade" : "A"
  },
  {
   "Name" : "Raj",
   "Result" : "Fail",
   "Grade" : "F"
  },
  {
   "Name" : "Howard",
   "Result" : "Pass",
   "Grade" : "B"
  }
 ]
}

I want to write a query which returns the elements with the "Result" : "Pass". I have tried ARRAY_CONTAINS() with query

SELECT * FROM d as c WHERE ARRAY_CONTAINS(c.Result, {"Result" : "Pass"}, true)

The Problem with the query is that it returns the whole of the array in as it is able to find "Result": "Pass" in the array. How should I modify or change the query such that the result contains only those elements of the array which has "Result": "Pass".

2 Answers 2

1

You just need to select the Properties

SELECT  c.Properties[0] as Result
FROM c
JOIN tag IN c.Properties
WHERE tag.Result = "Pass"
Sign up to request clarification or add additional context in comments.

2 Comments

Apparently, the query you suggested is also returning the whole array if one of the items of the array has "Result" : "Pass". I need only those items from the array which has "Result" : "Pass".
Not really, it returns only those object which has result pass.
0

Try this query which will return the id and only the matching items from the Properties array.

SELECT d.id, property FROM d JOIN property IN d.properties WHERE property.Result= "Pass"

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.