I am using the merge statement to do something like this - If the given docId exists return the doc else insert a default doc with given docId and return the doc.
My Query -
MERGE INTO testBucket AS t USING [{“id” : “123456”}] AS s
ON META(t).id = s.id
WHEN MATCHED THEN UPDATE SET t.value = t.value // This doesn’t feel great to me too
WHEN NOT MATCHED THEN INSERT (KEY s.id, VALUE {
“value” : “default”
})
RETURNING t.*, meta(t).id as __id, meta(t).cas as __cas
When insert is run, it doesn’t even return the cas. When update is run, it returns the last cas instead of the updated cas
If someone can suggest alternate query for the semantic that will be great too