[CXX-983] Misunderstanding about bsoncxx::document::element Created: 05/Aug/16 Updated: 08/Jan/24 Resolved: 08/Aug/16 |
|
| Status: | Closed |
| Project: | C++ Driver |
| Component/s: | API |
| Affects Version/s: | 3.0.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Andrey Kolkov | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
ubuntu 16_04 x64, gcc 5.4 |
||
| Description |
|
Is it correct to store bsoncxx::document::element in containers without storing bsoncxx::document::value (parental document)? I want to store a field from many documents and after transformation it to specific types... Like this:
|
| Comments |
| Comment by David Golden [ 09/Aug/16 ] |
|
For any pointer type, you need to keep the bsoncxx::document::value alive until you're done working with the data. Alternatively, you can copy the bytes out of the b_binary struct you get from get_binary and then let the document go. |
| Comment by Andrew Morrow (Inactive) [ 09/Aug/16 ] |
|
Be careful! A bsoncxx::types::value is just a union of the element types, so the same rules apply. You need backing storage for it. |
| Comment by Andrey Kolkov [ 09/Aug/16 ] |
|
Okay, I found "alternate approach" and I used bsoncxx::types::value instead of bsoncxx::document::element, but problem of converting to binary data preserved. |
| Comment by David Golden [ 05/Aug/16 ] |
|
A bsoncxx::document::element is a single-field view into a bsoncxx::document::value, so you do need to keep the parents around or come up with an alternate approach. |