[SERVER-19068] Server JSON parser doesn't preserve NumberLong type when parsing extended JSON Created: 22/Jun/15  Updated: 05/Feb/16  Resolved: 21/Sep/15

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 3.1.6

Type: Bug Priority: Major - P3
Reporter: Shaun Verch Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

The JSON parser uses the "appendNumber" function to append a NumberLong value to the resulting BSON object. However, this function chooses a different type depending on the value of the number: https://github.com/mongodb/mongo/blob/r2.6.0-rc1/src/mongo/bson/bsonobjbuilder.h#L234

This means that when using a NumberLong type in a JSON object that is being imported by mongoimport, the imported type can be an int, a double, or a long, depending on the value.

The solution would be to use "BSONObjBuilder::append" and force a specific type (as is done inside the "appendNumber" function).

Steps To Reproduce (using old tools which use the c++ parser):

$ cat input.json
{ "_id" : { "$oid" : "532205cba066bc569f1e8626" }, "x" : { "$numberLong" : "1" } }
{ "_id" : { "$oid" : "53220603dccaa782b7fdc2d9" }, "x" : { "$numberLong" : "4398046511104" } }
$ ./mongoimport --db test --collection test input.json
connected to: 127.0.0.1
2014-03-13T15:28:42.646-0400 imported 2 objects
$ ./mongo
MongoDB shell version: 2.6.0-rc2-pre-
connecting to: test
> db.test.find()
{ "_id" : ObjectId("532205cba066bc569f1e8626"), "x" : 1 }
{ "_id" : ObjectId("53220603dccaa782b7fdc2d9"), "x" : NumberLong("4398046511104") }
>

Or in c++ server code:

fromjson("{a:{$numberLong:1}}"}



 Comments   
Comment by Githook User [ 08/Jul/15 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-19068: treat NumberLong()/$numberLong as long long, always
Branch: master
https://github.com/mongodb/mongo/commit/21c4ce42c34008a966e66214b1dd83cdc066bf1c

Generated at Thu Feb 08 03:49:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.