Couchbase Transactions C++ Client  1.0.0
Transactions client for couchbase
Public Member Functions | Public Attributes | Friends | List of all members
couchbase::result Struct Reference

The result of an operation on a cluster. More...

#include <result.hxx>

Public Member Functions

CB_NODISCARD std::string strerror () const
CB_NODISCARD bool is_not_found () const
CB_NODISCARD bool is_success () const
CB_NODISCARD bool is_value_too_large () const
CB_NODISCARD bool is_timeout () const
CB_NODISCARD uint32_t error () const

Public Attributes

uint32_t rc
 return code for operation
uint64_t cas
 CAS for document, if any.
uint8_t datatype
 datatype flag for content
uint32_t flags
std::string key
 document key
boost::optional< nlohmann::json > value
 content of document
std::vector< subdoc_resultvalues
 results of subdoc spec operations
bool is_deleted
bool ignore_subdoc_errors


template<typename OStream >
OStream & operator<< (OStream &os, const result &res)

Detailed Description

The result of an operation on a cluster.

This encapsulates the server response to an operation. For example:

std::string key = "somekey";
result res = collection->get(key);
if (res.is_success()) {
auto doc = res.value.get<nlohmann::json>();
} else {
cerr << "error getting " << key << ":" << res.strerror();

If the operation returns multiple results, like a lookup_in, then result::values is used instead:

std::string key = "somekey";
result res = collection->lookup_in(key, {lookup_in_spec::get("name"), lookup_in_spec::get("address")});
if (res.is_success()) {
auto name = res.values[0].value->get<std::string>();
auto address = res.values[1].value->get<std::string>();
} else {
cerr << "error getting " << key << ":" << res.strerror();

If you define a to_json and from_json on an object, you can serialize/deserialize into it directly:

struct Person {
std::string name;
std::string address
to_json(nlohmann::json& j, const Person& p) {
j = nlohmann::json({ {"name",} , {"address", p.address}};
from_json(const nlohmann::json& j, Person& p) {"name").get_to(;"address").get_to(p.address);
auto res = collection.get(key);
if (res.is_success()) {
Person p = res.value->get<Person>();
cout << "name=" << << ",address=" << p.address;
} else {
cerr << "error getting " << key << ":" << res.strerror();

Member Function Documentation

◆ error()

CB_NODISCARD uint32_t couchbase::result::error ( ) const

Get error code. This is either the rc_, or if that is LCB_SUCCESS, then the first error in the values (if any) see subdoc_results

◆ strerror()

CB_NODISCARD std::string couchbase::result::strerror ( ) const

Get description of error

String describing the error code.

The documentation for this struct was generated from the following file: