Extended Attributes

Couchbase Server permits the definition of extended attributes. These allow developers to define application-specific metadata visible only to those applications that request it or attempt to modify it. This might be, for example, metadata specific to a programming framework that should be hidden by default from other frameworks, or possibly from other versions of the same framework.

Definition, Access, and Discovery

The Couchbase SDK supports the creation and modification of extended attributes by applications written in nodejs-sdk::sdk-xattr-example.adoc, java-sdk::sdk-xattr-example.adoc, dotnet-sdk::sdk-xattr-example.adoc, php-sdk::sdk-xattr-example.adoc, python-sdk::sdk-xattr-example.adoc, go-sdk::sdk-xattr-example.adoc, and c-sdk::sdk-xattr-example.adoc. This is achieved by extensions to the java-sdk::subdocument-operations.adoc. Extended attributes can be formed only as JSON, but can be applied to both JSON and binary items.

The creator-application can subsequently access and modify the extended attributes it has created within a document. However, Couchbase Server provides no facility for enumerating or sharing knowledge of extended attributes: therefore, no application has knowledge of the extended attributes within a document other than their creator; unless such knowledge is shared explicitly between applications by some mechanism external to Couchbase Server.

Implications for Sizing

Within Couchbase Server, the maximum size for each document is 20 megabytes (see the section Size Limits, on the page Data). Extended attributes count against this size-limit: consequently, the size of a document may reflect the presence of data inaccessible to some applications.

Virtual Extended Attributes

A virtual extended attribute exposes additional information about a document. Couchbase Server provides a single virtual extended attribute, $document, which, when specified as a search-path, returns metadata on the document. Ouput might appear as follows:

DocumentFragment
    {
      id='hotel_10138',
      cas=1504782798402879488,
      mutationToken=null
    }
    [
      GET($document)
        {
          value=
            {
              "exptime":0,
              "deleted":false,
              "CAS":"0x14e20ffb82ec0000",
              "seqno":"0x00000000000001fb",
              "datatype":["json","xattr"],
              "vbucket_uuid":"0x000060329233c341",
              "value_bytes":1504,
              "last_modified":"1504782798"
             }
         }
    ]