Change DOC Key via N1QL

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";

Thanks, just wondering why does the web interface report this if i run the query

success | elapsed: 14.60ms | execution: 14.33ms | mutations: 1 |

shouldn’t it report a fail or at least mutation of 0

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

In this case actual mutation happened. doesn’t mean document changed. It may be same document updated. If not it will return error.

In your case SET meta.id = “xxxxx”

  1. meta.id is not document key. because () missing, META().id is document key
  2. During set it looks for meta field. If not present or not OBJECT nothing is set. If Object id field is set inside meta.
  3. As there is no WHERE clause all documents qualify for update it means same document or updated document, SET controls what to SET.
  4. It