Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-19068

Server JSON parser doesn't preserve NumberLong type when parsing extended JSON

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.6
    • Component/s: Internal Code
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL

      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}}"}
      

        Attachments

          Activity

            People

            Assignee:
            scotthernandez Scott Hernandez
            Reporter:
            sverch Shaun Verch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: