I need to update a key in an array of objects where a key in the same object references a different document in the same bucket. On key is a uuid which points the primary key attachment::uuid in the same bucket. I’m trying this, but no luck:
UPDATE
table
SET
`evt`.`event_content`.`inline` = TOBOOLEAN(
(
select `t`.`inline`
from table as t use keys ['attachment::' || TO_STR(evt.attachment_id) ]
)[0].`inline`
)
FOR
evt in events
when evt.type = 'attachment_added'
END
If I hard code the id, it seems to do what I want for that id.
UPDATE table
SET `evt`.`event_content`.`inline` =
(SELECT RAW `t`.`inline` FROM table AS t USE KEYS ['attachment::' || TO_STRING(`evt`.attachment_id) ])[0]
FOR evt IN events WHEN evt.type = 'attachment_added' END;
[
{
"code": 5030,
"msg": "Missing or invalid primary key <nil> of type <nil>."
},
{
"code": 5030,
"msg": "Missing or invalid primary key <nil> of type <nil>."
}
]
If I remove the string concatenation: USE KEYS ['attachment::28952c55-40f3-4471-9431-0f81cf4ad5e7']
I do not get that error
CB version? post the document. The following seems to work.
insert into default values("kkk01",{"events":[{"event_content":{"inline":false},"attachment_id":1,"type":"attachment_added"}]});
insert into default values("attachment::1",{"inline":true});
UPDATE default
SET `evt`.`event_content`.`inline` =
(SELECT RAW `t`.`inline` FROM default AS t USE KEYS ['attachment::' || TO_STRING(`evt`.attachment_id) ])[0]
FOR evt IN events WHEN evt.type = 'attachment_added' END;
RAW can be used only when there is single projection. When RAW is present it removes one layer of object. In above case if no RAW you get out put as {“inline”:false}. If RAW present you get false.