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

Wrong BinData written with mongoimport

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.0-rc1
    • Affects Version/s: 2.4.0-rc0
    • Component/s: None
    • None
    • ALL

      Using this:

      t = new ToolTest( "jsonparser" );
      
      c = t.startDB("testcollection");
      
      data = 'data/jsonparser';
      
      key = "bindata";
      key_value = BinData(5, "nhB9nTcrtoJr2B01QqQZ1g==");
      c=t.db.getCollection("testcollection");
      // true is to enable field names to start with $
      // e.g. $undefined
      c.insert({key: key_value}, true);
      t.runTool( "export" , "--version");
      t.runTool( "export" , "--out" , data , "-d" , t.baseName, "-c" , "testcollection");
      c.drop();
      assert.eq( 0 , c.count() , "after drop" );
      t.runTool( "import" , "--version");
      t.runTool( "import" , "--file" , data , "-d" , t.baseName, "-c" , "testcollection2");
      c2=t.db.getCollection("testcollection2");
      assert.soon( "c2.findOne()" , "read imported document" );
      assert.eq( 1 , c2.count() , "1 doc after import" );
      
      var doc = c2.findOne();
      assert.eq( key_value , doc.key , "assert data type" );
      
      c2.drop();
      assert.eq( 0 , c2.count() , "after drop" );
      

      It works fine on 2.2.2.

      But not on 2.3.2 and 2.4.0-rc0

      assert: [BinData(5,"nhB9nTcrtoJr2B01QqQZ1g==")] != [BinData(5,"77+9EH3vv703K++/ve+/vQ==")] are not equal : assert data type
      Error: Printing Stack Trace
          at printStackTrace (src/mongo/shell/utils.js:37:7)
          at doassert (src/mongo/shell/assert.js:6:1)
          at Function.assert.eq (src/mongo/shell/assert.js:32:1)
          at test_round_trip (jsonparser-undefined.js:22:16)
          at jsonparser-undefined.js:31:1
      Wed Feb 20 16:38:16.332 [BinData(5,"nhB9nTcrtoJr2B01QqQZ1g==")] != [BinData(5,"77+9EH3vv703K++/ve+/vQ==")] are not equal : assert data type src/mongo/shell/assert.js:7
      failed to load: jsonparser-undefined.js
      

      mongoimport and mongoexport v2.4.0-rc0

      commandline:
      mongodb-osx-x86_64-2.4.0-rc0/bin/mongo --nodb --norc jsonparser.js

      mongoexport is saving

      { "_id" : { "$oid" : "5124fd42876fdb24f52e5722" }, "bindata" : { "$binary" : "nhB9nTcrtoJr2B01QqQZ1g==", "$type" : "05" } }
      

      but after running mongoimport, this is what appears on the shell

      {
        "_id": ObjectId("512503b4c35f6f6101d2b9c6"),
        "key": BinData(5, "77+9EH3vv703K++/ve+/vQ==")
      }
      

      note: even the objectid is different

      This doesn't occur with MaxKey(), NumberLong()

            Assignee:
            sverch Shaun Verch
            Reporter:
            gianfranco Gianfranco Palumbo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: