MongoDB C++ Driver 3.0 get document in string and avoid json
You can pull out the field you want directly as a double. To print high-precision output, you need to set that on the output stream. E.g.
for (auto&& doc : cursor) { std::cout << std::setprecision(15) << "lng: " << doc["lng"].get_double() << std::endl;}
Gives:
lng: -58.4682568037741
You may want to verify that doc["lng"]
is a BSON double before calling get_double
.