Is it possible to query couchbase via N1QL and use a select query to call insert statement to create a new DOC.
select _id, message from Contacts where _type = “track_request”
and then call
INSERT INTO Contacts ( KEY, VALUE )
VALUES
(
“message_body::” || uuid() ,
{ “_id”: uuid(), “_type”: “message_body”, “track_id” : _id, “body” : message}
)
assuming this is possible , is there also a way to temp declare a variable for the uuid() so that the key and _id will be same when it is created ?
I get as far as creating a new doc but tats where it ends with my luck, i looked into the samples but they dont do what i neeed. i dot want to go and copy the whole doc but only certain fields and be able to give the field a name other then in the original doc. In my case for example the meta().id will be stored as parent_id.
INSERT INTO `Contacts` (KEY "message_body::"|| k1, value t)
SELECT _id as k1, t._id,"message_body" as _type, meta(t).id as parent_id, t.message
FROM `Contacts` t
WHERE _type="track_request" LIMIT 1
INSERT INTO `Contacts` (KEY "message_body::"|| doc._id, value doc)
SELECT {t._id, "type":"message_body", "parent_id": meta(t).id, t.message } AS doc
FROM `Contacts` t
WHERE _type="track_request" LIMIT 1