I’m trying to set a property from an object that is inside an array on this case does not display errors, and it seems that it apply the changes to the number of objects that it should be but no changes are persisted.
This would be my collection:
[
{
"productName": "p00",
"characteristics": [
{
"name": "place x",
"value": [ {
"language": "",
"label": "\"Cool\""}
],
"characteristicId": "char00"
},
{
...
}
]
},
{
"productName": "p01",
"characteristics": [
{
"name": "place x",
"value": [{
"language": "",
"label": "\"Nice\""}, {...}
],
"characteristicId": "char00"
},
]
}
]
An this is the query:
UPDATE
Bucket_XXX
AS b
SET valueToUpdate.label = ‘[’ || valueToUpdate || ‘]’
FOR characteristic IN b.characteristics
FOR valueToUpdate IN characteristic.value
WHEN valueToUpdate.languageCode = ‘’ AND characteristic.characteristicId IN [‘char00’, ‘char01’] END
WHERE
(p.deleted = false)
AND
(ANY characteristic IN b.characteristics SATISFIES characteristic.characteristicId IN [‘char00’, ‘char01’] END)
I’ve tried to put the conditional to check if the characteristicId is valid on the first FOR to avoid looping inside the second FOR but it complains:
UPDATE
Bucket_XXX
AS b
SET valueToUpdate.label = ‘[’ || valueToUpdate || ‘]’
FOR characteristic IN b.characteristics WHEN characteristic.characteristicId IN [‘char00’, ‘char01’] END
FOR valueToUpdate IN characteristic.value
WHEN valueToUpdate.languageCode = ‘’ END
WHERE
(p.deleted = false)
AND
(ANY characteristic IN b.characteristics SATISFIES characteristic.characteristicId IN [‘char00’, ‘char01’] END)
The desired output should be for the first coincidence from: “label”: “"Cool"” to “label”: “["Cool"]”