[SERVER-80021] Make $convert round-trip correctly between double and string Created: 15/Aug/23  Updated: 15/Nov/23  Resolved: 14/Sep/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.2.0-rc0, 5.0.22, 6.0.11, 7.1.0-rc4, 7.0.3, 4.4.26

Type: Bug Priority: Major - P3
Reporter: Adi Agrawal Assignee: Adi Agrawal
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Cloners
is cloned by SERVER-81585 Address inconsistent floating point s... Closed
Problem/Incident
Related
related to SERVER-82775 Investigate whether v5.0_update_multi... Backlog
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.1, v7.0, v6.0, v5.0, v4.4
Steps To Reproduce:

db.c.aggregate([\{$project: {converted: {$convert: {input: 5909.123456, to: "string"}}}}]) gives 5909.12 .

Sprint: QE 2023-09-18
Participants:
Case:
Linked BF Score: 138

 Description   

We lose precision when we perform the conversion from double to string. Link to code. The default precision for a double in str::stream is set to 6 digits, which causes the loss of precision.

This problem was identified in HELP-48955.

We should change it so that we get a string representing the exact same doubleValue and can roundtrip and retrieve the same value back.

We also want comprehensive and randomized tests to verify this behavior. 



 Comments   
Comment by Githook User [ 26/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string

(cherry picked from commit 052ff0258ae00ed49e486e0a8acbffa81c7783d4)

SERVER-81077 Change ExpressionConvert test to convert double to string

(cherry picked from commit 39a130951177f23625ef56fec07aa49b4dc2878b)
Branch: v4.4
https://github.com/mongodb/mongo/commit/f4ce5439c121ba8834d38eb2e8cb94eeb4f33e1e

Comment by Githook User [ 22/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string

(cherry picked from commit 052ff0258ae00ed49e486e0a8acbffa81c7783d4)

SERVER-81077 Change ExpressionConvert test to convert double to string

(cherry picked from commit 39a130951177f23625ef56fec07aa49b4dc2878b)
Branch: v7.1
https://github.com/mongodb/mongo/commit/10917675e42af561849940d663da888ce614a49c

Comment by Githook User [ 20/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string

(cherry picked from commit 052ff0258ae00ed49e486e0a8acbffa81c7783d4)

SERVER-81077 Change ExpressionConvert test to convert double to string

(cherry picked from commit 39a130951177f23625ef56fec07aa49b4dc2878b)
Branch: v5.0
https://github.com/mongodb/mongo/commit/5175c0cdd5ed9a1fb9d6509d59a1ad24ce0389e8

Comment by Githook User [ 20/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string

(cherry picked from commit 052ff0258ae00ed49e486e0a8acbffa81c7783d4)

SERVER-81077 Change ExpressionConvert test to convert double to string

(cherry picked from commit 39a130951177f23625ef56fec07aa49b4dc2878b)
Branch: v6.0
https://github.com/mongodb/mongo/commit/5da4f25c4aa5dbc2efed07bc338ca20fb12060c4

Comment by Githook User [ 20/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string

(cherry picked from commit 052ff0258ae00ed49e486e0a8acbffa81c7783d4)

SERVER-81077 Change ExpressionConvert test to convert double to string

(cherry picked from commit 39a130951177f23625ef56fec07aa49b4dc2878b)
Branch: v7.0
https://github.com/mongodb/mongo/commit/142db09ea2d130682ec2feda579f37689972abe4

Comment by Githook User [ 14/Sep/23 ]

Author:

{'name': 'Adityavardhan Agrawal', 'email': 'adi.agrawal@mongodb.com', 'username': 'Adityav369'}

Message: SERVER-80021 Use format fmt to convert double to string
Branch: master
https://github.com/mongodb/mongo/commit/052ff0258ae00ed49e486e0a8acbffa81c7783d4

Generated at Thu Feb 08 06:42:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.