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

Bulk API downconversion does not return upsertedId with non-ObjectID _id

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Shell
    • ALL
    • Hide

      exports['Should correctly perform ordered upsert with custom _id'] = {
        // Add a tag that our runner can trigger on
        // in this case we are setting that node needs to be higher than 0.10.X to run
        requires: {serverType: 'Server'},
        
        // The actual test we wish to run
        test: function(configuration, test) {
          var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:false});
          db.open(function(err, db) {
            // Get the collection
            var col = db.collection('batch_write_ordered_ops_8');
            // Initialize the Ordered Batch
            var batch = col.initializeOrderedBulkOp();
       
            // Add some operations to be executed in order
            batch.find({_id:2}).upsert().updateOne({$set: {b:2}});
       
            // Execute the operations
            batch.execute(function(err, result) {
              // Check state of result
              test.equal(1, result.nUpserted);
              test.equal(0, result.nInserted);
              test.equal(0, result.nUpdated);
              test.equal(0, result.nModified);
              test.equal(0, result.nRemoved);
              
              var upserts = result.getUpsertedIds();
              test.equal(1, upserts.length);
              test.equal(0, upserts[0].index);
              test.equal(2, upserts[0]._id);
       
              // Finish up test
              db.close();
              test.done();
            });
          });
        }
      }

      Show
      exports['Should correctly perform ordered upsert with custom _id'] = { // Add a tag that our runner can trigger on // in this case we are setting that node needs to be higher than 0.10.X to run requires: {serverType: 'Server'}, // The actual test we wish to run test: function(configuration, test) { var db = configuration.newDbInstance({w:1}, {poolSize:1, auto_reconnect:false}); db.open(function(err, db) { // Get the collection var col = db.collection('batch_write_ordered_ops_8'); // Initialize the Ordered Batch var batch = col.initializeOrderedBulkOp();   // Add some operations to be executed in order batch.find({_id:2}).upsert().updateOne({$set: {b:2}});   // Execute the operations batch.execute(function(err, result) { // Check state of result test.equal(1, result.nUpserted); test.equal(0, result.nInserted); test.equal(0, result.nUpdated); test.equal(0, result.nModified); test.equal(0, result.nRemoved); var upserts = result.getUpsertedIds(); test.equal(1, upserts.length); test.equal(0, upserts[0].index); test.equal(2, upserts[0]._id);   // Finish up test db.close(); test.done(); }); }); } }

    Description

      When you perform an upsert with a custom _id the upserted field is not returned by GLE meaning the bulk api does not register it correctly as a upsert.

      Beneath is the node.js test that replicates this behavior

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            christkv Christian Amor Kvalheim
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: