[SERVER-309] fromjson modifies input int type to float Created: 23/Sep/09  Updated: 12/Jul/16  Resolved: 30/Nov/09

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: None
Fix Version/s: 1.1.4

Type: Improvement Priority: Minor - P4
Reporter: Valentin Kuznetsov Assignee: Mathias Stearn
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested on Mac OS X


Participants:

 Description   

Using the following C++ code the input document containing int type has been modified to float.

void insert(const string& host, const string& collection, const
string& json)

{ DBClientConnection c; c.connect(host); //"192.168.58.1"); BSONObj bobj = fromjson(json); c.insert(collection, bobj); }

For example supplying json string "

{\"test\":1}

" the resulting
document in mongo is

{"test": 1.0, "_id": "4ab936711725f62f42b01b44"}

This creates inconsistency and can lead to problem in applications who may check the types of values. It would be nice to fix it.
Thank you,
Valentin



 Comments   
Comment by Mathias Stearn [ 30/Nov/09 ]

The JSON parser now only creates doubles if the number has a decimal point

Comment by auto [ 30/Nov/09 ]

Author:

{'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: JSON parser now creates ints and longs SERVER-309
http://github.com/mongodb/mongo/commit/ce036039e6c23ef2c6fcb5344f1beb07aa251cb5

Comment by Dominik Gehl [ 03/Nov/09 ]

I came across this issue since the php driver's MongoGridFSFile::getSize function returned 0 even though the length field internally was ok ... but a float instead of an integer after I had exported/imported the gridfs data using mongoexport/mongoimport.

So this issue can not only generate issues in external applications, but also more hidden ones in the language drivers for example !

Generated at Thu Feb 08 02:53:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.