[CXX-673] How do you concatenate a view onto a sub_document? Created: 22/Sep/15  Updated: 16/Nov/21  Resolved: 21/Oct/15

Status: Closed
Project: C++ Driver
Component/s: API, Implementation
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Ethan Brown Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Issue Links:
Depends
depends on CXX-679 bsoncxx::basic::builder should suppor... Closed

 Description   

I'm wondering how to concatenate a document view onto an existing subview. Currently the _core is a private member variable, so my workaround was to fork the repo, make _core public and call:

sub_document o;
o._core->concatenate(view)

Is there a better way to do this?
Thank you in advance.



 Comments   
Comment by Andrew Morrow (Inactive) [ 21/Oct/15 ]

Fixed in CXX-679

Comment by Ethan Brown [ 21/Oct/15 ]

Yeah that's exactly what I needed, thanks!

Comment by Andrew Morrow (Inactive) [ 19/Oct/15 ]

etano - This should be resolved by the commit mentioned in CXX-679 on the master branch. Could you please try it and let me know if it works for your use case?

Comment by Andrew Morrow (Inactive) [ 07/Oct/15 ]

Hi etano - Yes, please see the work in CXX-679, on which this ticket depends. There is a pull request in review to add the necessary lower level features.

Comment by Ethan Brown [ 07/Oct/15 ]

Any update on this?

If I made a pull request where I just write a function to concatenate in basic::builder::document, what are the odds that it will be accepted?

Comment by Mira Carey [ 25/Sep/15 ]

Unfortunately not. While there's little currently in the way (the stream and basic builders are stateless outside of holding a single core object), I'm not sure I want to guarantee that forever. I'd much rather ensure that anything you can do with one, you can do with the other.

Comment by Ethan Brown [ 25/Sep/15 ]

Thanks for your help! The patch you describe would be perfect!

With the first route, the way I have things abstracted, I am given a basic::builder::document. Is there any way to safely cast a basic::builder::document into a stream::builder::document?

Comment by Mira Carey [ 24/Sep/15 ]

You're quite right, there's definitely a deficiency with the basic builder in terms of concatenation.

If you're looking for something that works out of the box now you can try the stream builder:

bsoncxx::builder::stream::document builder;
builder << "key" << "value" << bsoncxx::builder::stream::concatenate{doc_view};

which gives you:

{
    "key" : "value",
    // direct concatenation at this level of the keys and values in doc_view
}

I've also got a quick patch I'm going to start working through code review to add the same system to the basic builder, so you'll be able to:

 
bsoncxx::basic::builder::document builder;
builder.append(bsoncxx::basic::builder::concatenate{sub_doc});

I'll update this ticket once I have that up (though the final feature may evolve differently).

Generated at Wed Feb 07 21:59:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.