Merging JSONArray Documents from two buckets

Hi
Is there any way, where

  1. i can compare and update all the JSONArrayDocuments in bucket1 with the elements in bucket2, which has same keys…
    and
  2. at the same time if key dont exist in bucket 1, it should upsert/ insert the new key and respective JSONArrayDocument content from bucket2 to bucket1. Any N1QL query for that?

Example:

Bucket-1

Document key:1111

Content:

[{field1:000,field2:111},{field1:222,field2:333}]

Bucket-2

1st record in bucket-2

Document key:1111

Content:

[{field1:000,field2:aaa},{field1:ddd, field2:eee}]

2nd record in bucket-2

Document key:2222

Content:

[{field1:000,field2:aaa},{field1:ddd, field2:eee}]

so if i execute a N1QL query the bucket-1 should get updated as follows:

1st record in bucket-1

Document key:1111

Content:

[{field1:000,field2:aaa},{field1:ddd, field2:eee},{field1:222,field2:333}]

2nd record in bucket-1

Document key:2222

Content:

[{field1:000,field2:aaa},{field1:ddd, field2:eee}]

MERGE `bucket-1` AS t USING `bucket-2` AS s
ON KEY META(s).id 
WHEN MATCHED THEN UPDATE  SET t =  ARRAY_CONCAT(t, ARRAY v  FOR v IN s WHEN v NOT IN t END)
WHEN NOT MATCHED THEN INSERT  s ;

Thanks @vsr1 .That solved the issue . Just one small correction in the syntax

MERGE INTO bucket-1 AS t USING bucket-2 AS s
ON KEY META(s).id
WHEN MATCHED THEN UPDATE SET t = ARRAY_CONCAT(t, ARRAY v FOR v IN s WHEN v NOT IN t END)
WHEN NOT MATCHED THEN INSERT s ;