Couchbase C++ SDK 1.0

The Couchbase C++ SDK allows C++ applications to access a Couchbase cluster — Capella or self-managed.

What’s the point of a fast and scalable database if it’s not easy to develop for? Couchbase gives you the C++ APIs to work with Capella, our managed solution, or self-managed options in your private Cloud or datacenter.

  • Data Ops (CRUD)

  • SQL++ Query (OLTP)

auto collection = cluster.bucket(bucket_name).scope(scope_name).collection(collection_name);

const std::string document_id{ "minimal_example" };
const tao::json::value basic_doc{
        { "a", 1.0 },
        { "b", 2.0 },
};

auto [err, res] = collection.upsert(document_id, basic_doc, {}).get();
if (err) {
    fmt::println("Unable to perform upsert: {}", err);
} else {
    fmt::println("id: {}, CAS: {}", document_id, res.cas().value());
}
auto scope = cluster.bucket(bucket_name).scope(scope_name);

auto [err, resp] = scope.query("SELECT * FROM airline WHERE id = 10").get();
if (err) {
    fmt::println("Unable to perform query: {}", err);
}

for (const auto& row : resp.rows_as_json()) {
    fmt::println("row: {}", tao::json::to_string(row));
}
couchbase::search_request request(couchbase::vector_search(couchbase::vector_query("vector_field", vector_query)));

auto [err, res] = scope.search("vector-index", request).get();

if (err) {
    fmt::println("Got an error doing vector search: {}", err);
} else {
    for (const auto& row : res.rows()) {
        fmt::println("id: {}, score: {}", row.id(), row.score());
    }
}

Couchbase is a large platform — covering many services — and Couchbase SDKs are not thin wrappers generated around a REST API, but well thought out interfaces to the platform that make it easier to design and maintain your client code, and work with Couchbase in more natural ways for your platform. Install the SDK, and explore in the way that works best for you.

Building (command-line)
$ cd couchbase-cxx-client
$ mkdir build; cd build
$ cmake ..
$ cmake --build .

The links below will take you where you want to go — as will the navigation on the left-hand side of this page. But if you don’t know exactly where you need to go, try one of the following:

  • Our Quickstart Guide introduces the SDK with a quick install, and CRUD examples against the Data Service.

  • Couchbase’s familiar SQL-family query language and fuzzy search options (including vector search) are introduced on the Querying Your Data page.

  • The C++ SDK docs are, necessarily, just a sub-set C++ SDK API Reference — and a complete reference of all APIs can be found there.

  • For a fuller orientation, there is a guide to the C++ SDK docs


Using Your Database

Resources

Useful resources to help support your development experience with Couchbase and the C++ SDK.

Capella Columnar SDKs

SDKs for Capella Columnar — Couchbase’s analytical database (RT-OLAP) for real time apps and operational intelligence — are in development, and will be arriving first for the Java, Node.js, and Python platforms.