Couchbase::Document - Object represnting an item in the cluster.
my $doc = Couchbase::Document->new("id_string", ["content"]);
A document is the basic unit of the API and corresponds with an item as it is stored in the cluster. A newly created document exists only locally in the application, and must be submitted to the cluster via one of the methods in Couchbase::Bucket
Creates a new document object. A document object must have a non-empty ID which is used to associate this object with the relevant item on the cluster. If you desire to store the document on the cluster, you will also need to supply a value for the document.
Additional options may also be specified in the
$options hashref. The value for the options may also be set individually by accessor methods documented below.
Gets/Sets the ID for this document. The ID should only be set during creation of the document object.
Gets or sets the new value of the document. The value may be anything that can be encoded according to the document's "format()" property.
When retrieving a document (via the
get() method of Couchbase::Bucket), this field will be updated with the value stored on the server, if successful.
Get and set the storage format for the item's value on the cluster. Typical applications will not need to modify this value, but it may be desirable to use a special format for performance reasons, or to store values which are not representable in the default format.
Formats may be set either by specifying their numeric constants, or using a string alias. The following formats are recognized:
Stores the item as JSON. This is the default format and allows the value to be indexed by view queries. The value for the document must be something encodable as JSON, thus hashes, arrays, and simple scalars are acceptable, while references to strings, numbers, and similar are not.
Encodes the value using the
freezemethod of Storable. Use this format only for values which cannot be encoded as JSON. Do not use this format if you wish this value to be readable by non-Perl applications.
Stores the item as is, and marks it as an opaque string of bytes.
Stores the string as is, but flags it on the server as UTF-8. Note that no client-side validation is made to ensure the value is indeed a legal UTF-8 sequence.
The goal of this format is mainly to indicate to other languages (for example, Python or Java) which distinguish between bytes and strings that the stored value is a string. For Perl this is effectively like the
COUCHBASE_FMT_RAWformat, except that when retrieving the value, the
utf8flag is set on the scalar.
Specify the expiration value to be associated with the document. This value is only read from and never written to, and is used to determine the "Time to live" for the document. See "touch($doc)" in Couchbase::Document
Returns a boolean indicating whether the last operation performed on the cluster was successful or not. You may inspect the actual error code (and message) by using the "errnum()" and "errstr()" methods.
Returns the numerical error code of the last operation. An error code of
0 means the operation was successful. Other codes indicate other errors. There are also some convenient methods (below) to check for common error conditions.
Some of the error codes are documented in Couchbase::Constants.
Returns a textual description of the error. This should be used for informational purposes only
Returns true if the last operation failed because the document did not exist on the cluster
Returns true if the last operation failed because the local document contains a stale state. If this is true, the value should typically be retrieved, or the
ignore_cas option should be used in the operation.
Returns true if the last operation failed because the item already existed in the cluster. Check this on an