Actually, that won’t work for you as you have elements that are explicitly NULL and so can’t be matched for equality in the ARRAY_REPLACE. This should take care of that:
update bucket set `productComponents` =
(
select raw array_append(oth,object_add(o,"inventory",{
"invTypeId":301,
"viewId":13452547
}
)
)
from bucket b1
let o = (select raw ov
from bucket b2
unnest `productComponents` as ov
where b2.id = "appliedProduct_2_xxxxx"
and ov.`componentInstId` = 50811680
)[0]
, oth = (select raw otv
from bucket b3
unnest `productComponents` as otv
where b3.id = "appliedProduct_2_xxxxx"
and otv.`componentInstId` != 50811680
)
where b1.id = "appliedProduct_2_xxxxx"
)
where bucket.id = "appliedProduct_2_xxxxx"
;
UPDATE bucket b
SET pc.inventory = {"invTypeId":301, "viewId":13452547}
FOR pc IN b.`productComponents` WHEN pc.`componentInstId` = 50811680 END
WHERE b.id = "appliedProduct_2_xxxxx";