Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXXCBC-119: Set value of subdoc exists to "true" or "false" if result is success or path-not-found #452

Merged

Conversation

DemetrisChr
Copy link
Contributor

@DemetrisChr DemetrisChr commented Sep 18, 2023

Motivation

Path not found errors were cleared in #444. In addition to that, the value of the spec result should be set to the JSON representation of the exists field if the result was success or path-not-found. Relevant section of the RFC:

If the result came from an exists lookup, calls Exists to get a boolean, and uses the JSON representation of that boolean as the "value" in the next step. Propagates any exceptions thrown by Exists.

Changes

  • Set value to the JSON encoding of the exists boolean for exists spec results
  • Clear the path_not_found error in lookup_in_replica_request::make_response, to avoid having to duplicate the logic for lookup_in_any_replica and lookup_in_all_replicas. Remove the checks for a path_not_found error code everywhere that's no longer necessary because of this change.
  • Update the tests to reflect the change in the value of an exists subdoc result

Example

const std::string document_id{ "minimal_example" };
const tao::json::value basic_doc{
    { "a", 1.0 },
    { "b", 2.0 },
};
collection.upsert(document_id, basic_doc).get();

auto specs = couchbase::lookup_in_specs{
    couchbase::lookup_in_specs::exists("a"),
    couchbase::lookup_in_specs::exists("c")
};
auto [ctx, resp] = collection.lookup_in("minimal_example", specs).get();
std::cout << "Spec 0 - content (as bool): " << resp.content_as<bool>(0) << ", exists: " << resp.exists(0) << "\n";
std::cout << "Spec 1 - content (as bool): " << resp.content_as<bool>(1) << ", exists: " << resp.exists(1) << "\n";

will output

Spec 0 - content (as bool): 1, exists: 1
Spec 1 - content (as bool): 0, exists: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants