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

DBRef with NumberInt ID changing to float in the shell

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 3.6.3, 3.7.2
    • Affects Version/s: 3.2.7, 3.4.10, 3.6.0-rc4
    • Component/s: Shell
    • Labels:
      None
    • Fully Compatible
    • ALL
    • v3.6, v3.4, v3.2
    • Hide

      Run the following commands from the shell or as shell scripts

      • Step 1
        //insert a new row
        var currentId= ObjectId();
        db.test.insert({ 
            "_id" : currentId, 
            "string" : "1", 
            "int" : NumberInt(9087), 
            "float" : 1.1, 
            "refLong" : DBRef("ReferenceList", NumberLong(9087), "Reference"), 
            "refInt" : DBRef("ReferenceList", NumberInt(9087), "Reference")
        });
        
      • STEP2
        //fetch the row and save it again
        var doc = db.test.findOne({_id:currentId});
        //doc.refInt.$id = NumberInt(row.refInt.$id);
        db.test.save(doc);
        
      Show
      Run the following commands from the shell or as shell scripts Step 1 //insert a new row var currentId= ObjectId(); db.test.insert({ "_id" : currentId, "string" : "1" , " int " : NumberInt(9087), " float " : 1.1, "refLong" : DBRef( "ReferenceList" , NumberLong(9087), "Reference" ), "refInt" : DBRef( "ReferenceList" , NumberInt(9087), "Reference" ) }); STEP2 //fetch the row and save it again var doc = db.test.findOne({_id:currentId}); //doc.refInt.$id = NumberInt(row.refInt.$id); db.test.save(doc);
    • Platforms 2018-02-12

      I have a issue when fetching and saving documents in the shell have a DBRef id that is a NumberInt

      If you insert this document and then view the document json is fine

      { 
          "_id" : ObjectId(), 
          "string" : "1", 
          "int" : NumberInt(9087), 
          "float" : 1.1, 
          "refLong" : DBRef("ReferenceList", NumberLong(9087), "Reference"), 
          "refInt" : DBRef("ReferenceList", NumberInt(9087), "Reference")
      }

      But if you run a shell script that finds the document and then saves it again, the field "refInt" changes from

      • "refInt" : DBRef("ReferenceList", NumberInt(9087), "Reference")
        To
      • "refInt" : DBRef("ReferenceList", 9087.0, "Reference")

      The field "int" does not change

      I have checked a few versions and have the same issue

      When running the steps to reproduce, if you run only step one, the data is fine, if you run Step 2, dbref id changes from int to float

            Assignee:
            mira.carey@mongodb.com Mira Carey
            Reporter:
            plasticsnake simon hall
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: