I am trying to use the bsoncxx library to access records from mongdb using C++. however when i try to retrieve the element type as shown in the code below i get the error shown below. Ive been going round in circles trying to figure this out, but i feel stumped.
My error msg:
terminate called after throwing an instance of 'bsoncxx::v_noabi::exception'
what(): unset document::element.
My Code:
using namespace bsoncxx;
int main(int, char**) {
//const std::uint8_t* recdata;
//const std::uint8_t* elbytes[100000];
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
auto collection = conn["simpleemdb"]["priceCurves"];
auto cursor = collection.find({});
int counter =0;
for (auto&& doc : cursor) {
//recdata=doc.data();
if (counter ==0){
auto cEle= doc["curve_name"];
type eltype= cEle.type();
}
counter++;
}
}
can anyone help me understand why this is happening