[SERVER-11867] In strict-json mode, represent NumberLongs with strings Created: 26/Nov/13  Updated: 16/Jun/14  Resolved: 02/Dec/13

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

Type: Bug Priority: Critical - P2
Reporter: Eric Milkie Assignee: Shaun Verch
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-167 Support $numberLong for extended JSON... Closed
is depended on by SERVER-11659 Audit strict json output for auditing... Closed
is depended on by SERVER-6812 Extended JSON syntax should support a... Closed
Related
related to DOCS-2880 numberLong rep Closed
is related to SERVER-11136 Support json parsing of NumberLong/Int Closed
Operating System: ALL
Participants:

 Description   

Rather than represent numberlongs in strict json as a number, it should be represented as:

{ $numberLong: "12345" }



 Comments   
Comment by Bernie Hackett [ 11/Jun/14 ]

I don't think we can have the drivers encode native long types to $numberLong subdocuments in JSON instead of numbers. That's likely to break existing applications that use JSON, and $numberLong isn't supported by earlier server versions, tools, third party drivers, earlier versions of our drivers, etc.

We can easily decode from $numberLong to something appropriate for a given language, but it may be a lossy conversion. For example, in python 2 we would decode this to long, regardless of value. But in python 3 there is only an int type. We will lose the context that {$numberLong: "256"} should be encoded from python int(256) to BSON int64 instead of BSON int32.

Comment by Scott Hernandez (Inactive) [ 05/Dec/13 ]

Drivers: If you parse/output json then you should adopt the new format.

Docs: We need to add this to the release notes, extended json doc, and update tool examples (like mongoexport/bsondump).

mongoexport example:

> db.numbers.insert({n:1,i:NumberInt(1), l:NumberLong(1), d: new Date(), ts:new Timestamp() })
...
$ mongoexport -d test -c numbers
{ "_id" : { "$oid" : "52a0a61672a5f2f771099b54" }, "n" : 1, "i" : 1, "l" : { "$numberLong" : "1" }, "d" : { "$date" : 1386259990098 }, "ts" : { "$timestamp" : { "t" : 0, "i" : 0 } } }

bsondump example:

./bsondump /tmp/test/numbers.bson 
{ "_id" : ObjectId( "52a0a61672a5f2f771099b54" ), "n" : 1, "i" : 1, "l" : NumberLong(1), "d" : Date( 1386259990098 ), "ts" : Timestamp( 0, 0 ) }

Note: some of these changes came through with SERVER-11136, but we can track them here.

Comment by Githook User [ 04/Dec/13 ]

Author:

{u'username': u'Zarkantho', u'name': u'Shaun Verch', u'email': u'shaun.verch@10gen.com'}

Message: SERVER-11867 Do not use NumberLong constructor in JS JSON output mode
Branch: master
https://github.com/mongodb/mongo/commit/82a185ede3165175fc1a7adcd8c4e613571ff645

Comment by Githook User [ 02/Dec/13 ]

Author:

{u'username': u'Zarkantho', u'name': u'Shaun Verch', u'email': u'shaun.verch@10gen.com'}

Message: SERVER-11867 Support numberLong object in strict JSON
Branch: master
https://github.com/mongodb/mongo/commit/bad97aeec714c895fa23ee90aebbffeacc6d621d

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