-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
None
Currently, to create an owning bson_value::value, users must first construct a bsoncxx::document::value, then parse out the bson_value they are interested in:
auto doc = make_document(kvp("v", "message")); auto owning_value = doc.view()["v"].get_owning_value();
This is not an ideal workflow. To avoid it, we will need to provide a way for users to construct bson_value::value directly. We should not utilize the b_type structs for this, because those structs are inherently non-owning, and would require a copy for us to use them to implement these constructors. Instead, we should consider exposing a series of bson_value::value constructors that take the component members for each b_type.
For example, something like:
// constructor for b_document value(document::view_or_value doc); // constructor for b_oid value(oid object_id); // constructor for b_regex value(std::string regex, std::string pattern); // constructor for b_binary value(binary_sub_type sub_type, uint32_t size, std::unique_ptr<uint8_t[]> bytes);
With such constructors the workflow would be simpler and more straightforward:
bson_value::value owning_value{"message"};