From 5356624a1dcff62d130ece8c75b86a2055894116 Mon Sep 17 00:00:00 2001 From: Sergey Avseyev Date: Wed, 26 Jun 2024 14:32:17 -0700 Subject: [PATCH] Add document reading to minimal example --- examples/minimal.cpp | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/examples/minimal.cpp b/examples/minimal.cpp index e28403b..4756437 100644 --- a/examples/minimal.cpp +++ b/examples/minimal.cpp @@ -46,16 +46,31 @@ main() .collection(config.collection_name); const std::string document_id{ "minimal_example" }; - const tao::json::value basic_doc{ - { "a", 1.0 }, - { "b", 2.0 }, - }; - auto [err, resp] = collection.upsert(document_id, basic_doc, {}).get(); - if (err.ec()) { - std::cout << "ec: " << err.message() << ", "; + { + const tao::json::value basic_doc{ + { "a", 1.0 }, + { "b", 2.0 }, + }; + + auto [err, resp] = collection.upsert(document_id, basic_doc, {}).get(); + std::cout << "Upsert id: " << document_id; + if (err.ec()) { + std::cout << ", Error: " << err.message() << "\n"; + } else { + std::cout << ", CAS: " << resp.cas().value() << "\n"; + } + } + { + auto [err, resp] = collection.get(document_id, {}).get(); + std::cout << "Get id: " << document_id; + if (err.ec()) { + std::cout << ", Error: " << err.message() << "\n"; + } else { + std::cout << ", CAS: " << resp.cas().value() << "\n"; + std::cout << tao::json::to_string(resp.content_as()) << "\n"; + } } - std::cout << "id: " << document_id << ", CAS: " << resp.cas().value() << "\n"; } cluster.close().get();