[CXX-2067] Expose bson_value::value type constructors Created: 07/Jul/20  Updated: 28/Oct/23  Resolved: 22/Oct/20

Status: Closed
Project: C++ Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 3.7.0, 3.7.0-beta1

Type: Improvement Priority: Major - P3
Reporter: Samantha Ritter (Inactive) Assignee: Clyde Bazile III (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by CXX-1455 Add JSON-like syntax to construct BSO... Closed
Related
is related to CXX-2066 implement a make_value helper Closed
Epic Link: CXX-2082

 Description   

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

 



 Comments   
Comment by Githook User [ 22/Oct/20 ]

Author:

{'name': 'Clyde Bazile', 'email': '34226620+bazile-clyde@users.noreply.github.com', 'username': 'bazile-clyde'}

Message: CXX-2067 Expose bson_value::value type constructors (#725)
Branch: master
https://github.com/mongodb/mongo-cxx-driver/commit/e57b4ec02e1831c533f22e0b11e17046801508ea

Comment by Clyde Bazile III (Inactive) [ 12/Oct/20 ]

https://github.com/mongodb/mongo-cxx-driver/pull/725

Generated at Wed Feb 07 22:04:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.