Uploaded image for project: 'C++ Driver'
  1. C++ Driver
  2. CXX-2067

Expose bson_value::value type constructors

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.7.0, 3.7.0-beta1
    • Affects Version/s: None
    • Component/s: None
    • Labels:

      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"}; 


            clyde.bazile@mongodb.com Clyde Bazile III (Inactive)
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            0 Vote for this issue
            3 Start watching this issue