I was wondering if there is a way to change the meta().id / Doc Key for a doc in couchbase. i tried to update meta().id or meta.id and even so query says mutations 1 nothing changed
update Contacts
USE Keys "leadbucket::01FD918F-2D4D-4453-A965-846914E410CC"
set meta.id = "bucket::01FD918F-2D4D-4453-A965-846914E410CC"
so my question is can i via N1QL update a doc key ?
In Couchbase Document key is Immutable. You can’t change it.
Solution: Insert as new document with new key and delete old one.
INSERT INTO Contacts (KEY _k, VALUE _v)
SELECT SUBSTR(META(c).id,4) AS _k , c AS _v
FROM Contacts AS c USE KEYS "leadbucket::01FD918F-2D4D-4453-A965-846914E410CC";
DELETE FROM Contacts USE KEYS "leadbucket::01FD918F-2D4D-4453-A965-846914E410CC";
update Contacts
USE Keys "leadbucket::01FD918F-2D4D-4453-A965-846914E410CC"
set meta.id = "bucket::01FD918F-2D4D-4453-A965-846914E410CC"
Above statement is adding meta.id as field name if there is meta object present in the document.
Please note mutation count only tells how many documents qualified for mutation ( in your case no WHERE clause if document present it qualifies). It doesn’t tell it really mutation happened or not.
thanks that makes this a bit more clear , would be nice if the mutation would actually report how many docs have been updated/mutated rather then show how many would meet the where clause in my case its 1 since i use keys