N1QL query similair to for loop with counter increment

Hi,
I am not sure in looping through an index of array elements to check if the elements have same value
I have a document with array. The array has “n” number of elements.
For eg:
“results”: [
{
“out”: {
“name”: “a”,
“age”: “4”,
“class”: abc
}
},
{
“out”: {
“name”: “b”,
“age”: “5”,
“class”: abc
}
}
]
I need to check if the value of class in all the elements of array are equal.The value of class is dynamic so we cannot compare it to an exact string.Now the size of this array is 2. But the size will also vary.
It is similiar to for loop looping over the length of array and checking the value of all index of specific array element are same

SELECT META().id FROM default WHERE EVERY v IN results SATISFIES v.class = results[0].class END;

Thanks @vsr1. I tried this query it runs successfully but does not return anything

I used default bucket and you don’t have any data or matching data. Please try where you have matching data it gives. Or post your exact query and input document and expected output.

I have the document in default bucket.
Input document:
“results”: [
{
“origin”: {
“name”: “a”,
“age”: “4”,
“class”: abc
}
},
{
“origin”: {
“name”: “b”,
“age”: “5”,
“class”: abc
}
}
]

N1QL Query:

SELECT origin FROM default AS out UNNEST out.origin as origin WHERE (out.origin[0].class!=out.origin[1].class);
I need to modify this query as generic one without mentioning the index as [0] or [1].
The origin can be any numbers dynamically changing so the query should work for any number of origins.

Expected result:
I want to filter out the origins whose class value is not same.

INSERT INTO default VALUES("k00",{"origin":[ ] });
INSERT INTO default VALUES("k01",{"origin":[ { "name": "a", "age": "4", "class": "abc" }, { "name": "b", "age": "5", "class": "abc" }, { "name": "c", "age": "6", "class": "abc" } ] });

INSERT INTO default VALUES("k02",{"origin":[ { "name": "a", "age": "4", "class": "abc1" }, { "name": "b", "age": "5", "class": "abc" }, { "name": "c", "age": "6", "class": "abc" },{ "name": "aa", "age": "14", "class": "abc2" } , { "name": "abc", "age": "34", "class": "abc2" },{ "name": "ab", "age": "24", "class": "abc2" }] });

SELECT d.origin FROM default AS d WHERE NOT (EVERY v IN d.origin SATISFIES v.class = d.origin[0].class END);

The query projects whole array when all the elements are not matched. If you need specific one based on your requirement you can reconstruct array from original array.

@vsr1
It works as charm. Thanks a lot for the query.