A few points:
- Not possible to set TTL via N1QL
- You should first validate the MERGE statement using cbq shell, and then move the statement to your application
MERGE INTO myBucket
USING (SELECT NULL) AS d ON KEY $key
WHEN MATCHED THEN UPDATE SET …
WHEN NOT MATCHED THEN INSERT …
;