I am in need to move a large amount of docs between two buckets on the same server. Based on the sample found
INSERT INTO `travel-sample` (KEY UUID(), VALUE _country)
SELECT _country FROM `travel-sample` _country
WHERE type = "airport" AND airportname = "Heathrow"
RETURNING *;
i was wondering if there is a way to copy the whole doc without specifying all the fields to copy /insert into the new doc and also use some values from the old doc like _type and _id to construct a new key which is same as the old one. Or is there a way to get the meta().id to use the same key as the original id. If i take all fields from the source doc, how can i add like a field of _type=‘message’ ? to the doc being saved ?
Finally is there a way to delete the source doc automatically after the new doc has been created ?
INSERT INTO `travel-sample` (KEY id, VALUE doc)
SELECT META(t).id AS id, OBJECT_ADD(t,"_type", "message") AS doc FROM `travel-sample` t
WHERE t.type = "airport" AND t.airportname = "Heathrow";
If you want different key you can construct it either in select projection or INSERT
example: (KEY “message::”||id , VALUE doc ) …
If u planning to use UUID() if repeat command there might be duplicates because each time it gets different key.
You can also use UPSERT …
If large amount of data you can choose other options.
What would the syntax be if i want to add 2 objects like _type and _id.
There wont be a duplicate key issue as its a one time import into a different bucket