While experimenting with the C++11 driver of MongoDB (version 3.1.0-rc0) the output of the following piece of code confused me.
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
int main() {
bsoncxx::builder::stream::document s;
s << "x" << 1.0;
std::cout << bsoncxx::to_json(s) << std::endl;
return 0;
}
Output:
{ "x" : 1 }
Configuration: CentOS 7, gcc 6.2.0, mongo-c-driver 1.5.0, mongo-cxx-driver 3.1.0-rc0
It looks like that behavior is inherent to libbson, which provides the JSON serialization. It's sort of technically correct, since Javascript doesn't distinguish numeric types, but I understand how you'd prefer it to keep the decimal component, even if 0.
So at the moment, the answer to your questions are
I'll take up the issue with the libbson maintainers as well. (Update: Filed ticket CDRIVER-1945).