A newer version of this documentation is available.

View Latest

Extended Attributes

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

    Using Extended Attributes

    The SDK supports extended attributes by means of extensions to the Sub-Document API: so that extended attributes can be defined, searched for, edited, removed, and more. In order to specify that a subdocument operation should be performed on an extended rather than a regular attribute, an xattr flag should be set to true, by the calling application. For detailed information on the Subdocument API, see Subdocument Operations.

    For more information, see Extended Attributes, and our example code.

    The maximum content size for a document stored in Couchbase Server is 20MB. XATTRs — including Virtual XATTRs — will reduce the space available for the remainder of the document.

    Language-Specific Variations

    Each language supported by the Couchbase SDK implements extended-attribute support in a slightly different way. For Python examples, see Sample Code.

    For detailed information on the Subdocument API, see Subdocument Operations.

    Virtual Extended Attributes

    Virtual extended attributes consist of metadata on an individual document: this can be retrieved by specifying $document as a search-path. For example:

    import couchbase.subdocument as SD
    frag = bucket.lookup_in("test", SD.get("$document", xattr=True))

    See the Virtual XATTR Section for more information on the metadata that they expose.

    These attributes are generated on-demand to expose storage-level document metadata, such as TTL to expose document expiration. For TTL using Virtual XATTR, use the following:

    import couchbase.subdocument as SD
    frag = bucket.lookup_in("test",SD.get("$document.exptime", xattr=True))

    See the example page for a complete code sample.