I am trying to extract data from MongoDB using the C++ driver.
I am able to successfully run a find query and can print the json string to the terminal, however I cannot figure out how to extract the data from the cursor. Ideally I don’t want to convert the data to a json string, and then parse the string, as that sounds like an unnecessary round trip. (is that assumption true?)
Is there a way to directly access the column values from the cursor, without needing to create a json string.
My code is below:
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
auto collection = conn["simpleemdb"]["priceCurves"];
auto cursor = collection.find({});
for (auto&& doc : cursor) {
At this point i would like to extract the document values.
For example i have a field in this collection called “curve name”,
I would like to do something like
curvename[i] = doc.getField("curve name")
Is that possible, or what options do I have. Any help with this would be greatly appreciated.
Please note performance is a large concern, so the most efficient method would be appreciated.