I am accessing data from MongoDB using the C++ driver, and have written the following code to extract data from the database.
From testing, it takes around 20 seconds to extract 100 documents with 5 values each.
I achieve this by running 4 threads at once. This however is too slow for my purposes. is there a quicker way to access the data than the cursor, as the cursor seems to be the bottleneck at the moment. please note the function records.extractRecord is simply a wrapper around extracting the data from the Bson Types.
for (bsoncxx::document::element ele : doc) {
bsoncxx::stdx::string_view field_key{ ele.key() };
savelocation = -1;
switch (ele.type()) {
case bsoncxx::type::k_double:
records.extractRecord(ele.get_double(), field_key.to_string(), threadNumber, recordCount);
//extractedvalue = std::to_string(ele.get_double());
break;
/*case bsoncxx::type::k_utf8:
savelocation = records.extractRecord(boost::string_view(ele.get_utf8()).to_string(), field_key.to_string(), threadNumber, recordCount);
extractedvalue = boost::string_view(ele.get_utf8()).to_string();
break;*/
case bsoncxx::type::k_date:
records.extractRecord((int64_t)ele.get_date(), field_key.to_string(), threadNumber, recordCount);
//extractedvalue = std::to_string((int64_t)ele.get_date());
break;
case bsoncxx::type::k_int32:
records.extractRecord((int32_t)ele.get_int32(), field_key.to_string(), threadNumber, recordCount);
//extractedvalue = std::to_string((int32_t)ele.get_int32());
break;
case bsoncxx::type::k_int64:
records.extractRecord((int64_t)ele.get_int64(), field_key.to_string(), threadNumber, recordCount);
extractedvalue = std::to_string((int64_t)ele.get_int64());
break;
}