Trying to merge from one bucket to another, where the document id has a prefix

The source aliased to h, So u need to use alias name every where. Assume orderId is always string.

MERGE INTO order as o USING history AS h ON KEY 'order::' || h.orderId
WHEN MATCHED THEN UPDATE SET o.paidDate = h.date