The scope of variable v only with in the ANY clause (ANY v IN t.SupportArray SATISFIES v.id = “GK315baf” END), outside it is not visible. So u can’t use in SET clause.
Use new ARRAY constructs.
UPDATE TY t
SET t.SupportArray = ARRAY v1 FOR v1 IN t.SupportArray WHEN v1.id != "GK315baf" END
WHERE ANY v IN t.SupportArray SATISFIES v.id = "GK315baf" END;
“code”: 4000,
“msg”: “No index available on keyspace Notification that matches your query. Use CREATE INDEX or CREATE PRIMARY INDEX to create an index, or check that your expected index is online.”
FOR v1 IN t.SupportArray takes every element of array
WHEN v1.id != “GK315baf” If condition is true then
append into new array of expression v1 ( i.e expression between ARRAY and FOR)
if condition is false ignores that element and moves to next element
ARRAY, FIRST, and OBJECT
Range transforms (ARRAY, FIRST, OBJECT) allow you to map and filter the elements or attributes of a collection or object(s). ARRAY evaluates to an array of the operand expression, while FIRST evaluates to a single element based on the operand expression. OBJECT evaluates to an object whose name : value attributes are name-expr : expr .
Name-expr must evaluate to a string. If not, that attribute is omitted from the result object.
UPDATE TY t
SET t.SupportArray = ARRAY v1
FOR v1 IN t.SupportArray
WHEN (v1.id != “GK315baf” END)
WHERE ANY v IN t.SupportArray SATISFIES v.id = “GK315baf” END;
If Index is not using check Index is Built and provide the output of
select * from system:indexes where name = " idx_ns2_id";
UPDATE TY t
SET t.SupportArray = ARRAY v1 FOR v1 IN t.SupportArray WHEN (v1.id != "GK315baf") END
WHERE ANY v IN t.SupportArray SATISFIES v.id = "GK315baf" END;
it’s returned the response but the query throw the same exception “code”: 4000,
“msg”: "No index available on keyspace TY that matches your query.
[
{
“indexes”: {
“datastore_id”: “”,
“id”: “764990bd37819c12”,
“index_key”: [
“(distinct (array (v.id) for v in SupportArray end))”
],
“keyspace_id”: “TY”,
“name”: “idx_ns2_id”,
“namespace_id”: “default”,
“state”: “online”,
“using”: “gsi”
}
}
]
It works for me. What is Couchbase version you are using.
If still has issue post screen shot of query and error
EXPLAIN UPDATE `TY` t
SET t.SupportArray = ARRAY v1 FOR v1 IN t.SupportArray WHEN (v1.id != "GK315baf") END
WHERE ANY v IN t.SupportArray SATISFIES v.id = "GK315baf" END;