Fastest way to copy document and modify content before saving

Hi
I have a need to make copy of json document I will retrieve based on some key but save it with different Key and “id” attribute within the same bucket. Please note the "id " attribute value should be same as Key of the new copied document. I don’t know the other attributes and values of the document as it gets decided at runtime. FYI, I am using C# SDK.
I tried the below query but how do I change the “id” attribute value of the copied document:

INSERT INTO bucket(KEY UUID(), VALUE v) SELECT v FROM bucket WHERE id=“xyz”

Since the document I pick is decided at runtime, I wont know the other attributes to frame my SELECT query. All I have to do is find the fastest way to copy entire document with all attributes and only change KEY and “id” attribute value before saving it again.

If you know the key and using C#SDK use KV get and Add(write) as different key

OR

INSERT INTO `bucket` (KEY v.id, VALUE v) 
SELECT OBJECT_PUT(d, "id", newkey) AS v  FROM  `bucket` AS d USE KEYS "xyz"
LET newkey = UUID()
1 Like

This is just awesome