-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.17.4
-
Component/s: libbson
-
None
The bson_as_relaxed_extended_json() is not showing correctly doubles. In particular, if I had:
doc = bson_new (); bson_oid_init (&oid, NULL); BSON_APPEND_OID (doc, "_id", &oid); BSON_APPEND_DOUBLE (doc, "d1", -3.691944); BSON_APPEND_DOUBLE (doc, "d2", 40.418889); char* bsonStr = bson_as_relaxed_extended_json(doc, NULL); fprintf(stdout, "%s\n", bsonStr); bson_t *opt = BCON_NEW("validate", BCON_BOOL(false)); if (!mongoc_collection_insert_one ( collection, doc, opt, NULL, &error)) { fprintf (stderr, "ERROR: %s\n", error.message); }
(I have included only the relevant part of my program for the sake of briefness, but of course, the full code is available if you need it)
What I see in my output is:
{ "_id" : { "$oid" : "605deb4b0547463a2521fcd2" }, "d1" : -3.6919439999999998925, "d2" : 40.418889000000000067 }
instead of (i.e. my expectation):
{ "_id" : { "$oid" : "605deb4b0547463a2521fcd2" }, "d1" : -3.691944, "d2" : 40.418889 }
However, in the DB the data is inserted correctly:
> db.mycoll.find() { "_id" : ObjectId("605dea3e23a3171905115392"), "d1" : -3.691944, "d2" : 40.418889 }
Not sure if other functions that also render JSON strings have the same problem. I have checked only bson_as_relaxed_extended_json().
Maybe I'm doing something wrong?
Thanks!
- duplicates
-
CDRIVER-3812 bson_as_json outputs illegal JSON for some locales
- Backlog
- is related to
-
CDRIVER-3812 bson_as_json outputs illegal JSON for some locales
- Backlog
-
CDRIVER-2063 JSON export prints insignificant digits / noise
- Closed
- related to
-
CDRIVER-4819 Allow reducing precision when converting BSON double values to JSON
- Backlog