[CDRIVER-1938] bson_as_json converts int64 to scientific notation Created: 28/Nov/16  Updated: 11/Sep/19  Resolved: 28/Feb/17

Status: Closed
Project: C Driver
Component/s: json, libbson
Affects Version/s: 1.3.5
Fix Version/s: 1.7.0

Type: Task Priority: Major - P3
Reporter: Darin Christenson Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Epic Link: libbson corpus

 Description   

When trying to retrieve an int64 value using mongoc_collection_find, mongoc_cursor_next, and bson_as_json, I need to see the full value. When I run the code now, it translates my value into scientific notation, which loses precision (e.g., 1479421652125003000 becomes 1.479421652125e+18).

Is there any way to get the actual value instead of the scientific notation value?



 Comments   
Comment by Githook User [ 24/Feb/17 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-1947 generate int64 as $numberLong

Fixes CDRIVER-1938, there is now a lossless format for int64.
Branch: master
https://github.com/mongodb/libbson/commit/15122b281e24785b0f2a74bc1667915253a1db7f

Comment by A. Jesse Jiryu Davis [ 28/Nov/16 ]

Hi Darin. Currently, no, there's no way to make bson_as_json produce exact output. We've discussed this in CDRIVER-375, so far we haven't specified a feature for MongoDB drivers for exact JSON output. Likely, we will some day provide you the option of outputting int64's as $numberLong: "123", the same as the input format.

Meanwhile, you can certainly read the exact value in C with bson_iter_as_int64, but you'll need to convert the result to a string yourself in order to preserve precision.

Generated at Wed Feb 07 21:13:40 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.