The NaN handling is different between the C driver and older versions of the C++ driver.
We are using version 2.6.5 of c++ 26compat version.
When we call fromjson on a json containing a NaN value, the C++ driver won't complain and will keep it as NaN.
However, doing the same with C driver will give us an error and an empty bson document.
for example, using this code:
BSONObj obj = fromjson( "{ \n" " \"DOUBLE\" : 2.25, \n" " \"INT\" : 9999, \n" " \"ARRAY\" : [ \n" " { \"Name\" : \"Meier\", \"age\" : 90 }, \n" " { \"Name\" : \"Smith\", \"age\" : 80 } \n" " ] , \n" " \"VEC\" : [ NaN, 3, 5, 7, 11, 13] \n" "} \n" );
we will obtain the desired BSONObj with NaN
and we have the following implementation for fromjson using libmongoc
BSONObj fromjson(const std::string& str) { bson_t doc; bson_error_t error; if (!bson_init_from_json(&doc, str.c_str(), static_cast<long long>(str.size()), &error)) { std::cout<< "fromjson ERROR: " << error.domain << "." << error.code << ": " << error.message << std::endl; bson_destroy(&doc); return BSONObj(); } return BSONObj(&doc); }
In this case, the code will enter to the error case and doc will be empty
- depends on
-
CDRIVER-1370 Replace libyajl with jsonsl
- Closed
- is related to
-
CDRIVER-1336 Define constants for special strings returned by bson_decimal128_to_string()
- Closed