I’m writing c++ code that needs to jive with existing c code.
The structure in question has an array of bson_t entries, and I need to create a bsoncxx::document::view from the bson_t objects (to port them to a bsoncxx structure).
What is the easiest way to do this? Am I overthinking it, that is to say, is bson_t compatible to just append to, for example, a bsoncxx::builder::basic::array?
Do I need to access the data buffer and initialize a bsoncxx::document::view manually, and if so, how do I access the buffer from a bson_t pointer?
Sorry for any lack of clarity, and I assure you I have been googling this for a while.
Thanks for the response! Is there any way to do such a conversion without using the bson library, like accessing the actual data without the bson api? I’m not sure how to explain it but I’d much rather not handle bson_t at all, I feel like using both libbson and bsoncxx kind of defeats the point of lifting my module to a later standard.
Where is the array of bson_t entries coming from? Could they pass the underlying data instead?
Even if you have both libbson and bsoncxx together, wouldn’t it be the case only till you port your data over? In other words, wouldn’t this migration be done at some point in time, where you could just start using bsoncxx only with no need of porting?
I’m connected to a capped mongodb collection that is used as a data queue (or maybe more accurately like a stream…). I am not able to change the incoming data, unfortunately. So far, I am only working on one out of many consuming submodules. Structural change would definitely be the best solution yet I am not in the position to make any decisions with repercussions toward other submodules.
So, just to make sure I understand correctly, is this an accurate representation of your situation? You can make changes only in your code, and only want to use bsoncxx/mongocxx?
Note: I am assuming here that your code can’t directly connect to MongoDB collection. If you can, then you can directly fetch the BSON documents using the C++ driver into a bsoncxx document.
Wow. Yes this is accurate enough, the specifics are that my module IS a consumer but has to adhere to a standard defined somewhere upstream and used by all other consumers (bson_t in a predefined structure).
Is your code making direct connection to the MongoDB collection?
Who is responsible for fetching the BSON docs from MongoDB collection and populating it with bson_t?