Returning statement after Merge statement returns the older cas value

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 =
WHEN MATCHED THEN UPDATE SET t.value = t.value // This doesn’t feel great to me too :frowning:
“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 :slight_smile:

That is true. once mutation happens we don’t get/retrieve the new cas from the KV. That is the reason cas value on RETURNING statements are not the new one.

Track via MB-43604