Storing id in the document - is there a reason?

We will use doc_type::uuid format for the Couchbase document key. The key will not be stored in the document, just in the metadata. Is there any reason to store the uuid separately in the document field (it is randomly generated, so it serves just as an id). Seemingly, one does not need to store the doc_type field either as it can be extracted from the full key in the metadata in case of a creating a view, etc.

What is recommended as best practice?

Thank you,
– Alex

there is no reason to dup the doc key inside the document value one more time. you’d be wasting a lot of space to do this.

Great, thanks! How about the doc_type? All examples have it, but it can be extracted from the key if it is part of it.

I also do not store id in the document just in the metadata as it is waste of space. As metadata are stored in RAM is there guarantee that these metadata won’t be lost? Are these metadata replicated in case something goes wrong with one server? My main concern is that I am using ids as reference to other documents so when I lose these ids which are store in metadata than I have big problem. Thanks

All data related to a document (key, value, TTL, flags, etc) is persisted - assuming you’re using a Couchbase bucket. Additionally all that data is replicated to other nodes if you have one or more replicas configured.

(I don’t know how the system would work if it didn’t also store document keys!)