Uploaded image for project: 'MongoDB Database Tools'
  1. MongoDB Database Tools
  2. TOOLS-799

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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.0.0
    • Affects Version/s: None
    • Component/s: mongoimport

      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:

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

            Assignee:
            shraya.ramani Shraya Ramani
            Reporter:
            sverch Shaun Verch
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: