-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
Summary
The collection methods find_one_and_update, find_one_and_delete, and find_one_and_replace raise an unexpected exception when an unacknowledged write concern is used.
Background
This is caused by attempting to read a non-existent value from the reply.
How to Reproduce
Here is an example test to reproduce:
TEST_CASE("find_one_and_update works with unacknowledged write concern", "[collection]") { instance::current(); mongocxx::client client{uri{}, test_util::add_test_server_api()}; mongocxx::write_concern wc; wc.acknowledge_level(mongocxx::write_concern::level::k_unacknowledged); auto collection = client["fam_wc"]["collection"]; collection.drop(); collection.insert_one(make_document(kvp("x", 1))); stdx::optional<bsoncxx::document::value> doc; mongocxx::options::find_one_and_update find_one_and_update_opts; find_one_and_update_opts.write_concern(wc); // find_one_and_update gets an exception with message: // "cannot return the type of uninitialized element: unset document::element" doc = collection.find_one_and_update( {}, make_document(kvp("$set", make_document(kvp("x", 2)))), find_one_and_update_opts); REQUIRE(!doc); }
- is related to
-
CXX-2347 Allow hint for unacknowledged writes using OP_MSG when supported by the server
- Closed