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

Can you suggest any alternate query that can work for the same semantic?

I would also like to resolve this issue

This will be fixed in upcoming 7.0.0