Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-151

Handle Bulk API edge case for pre-2.6 servers when upserted _id not returned

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: None
    • Labels:
      None
    • $i18n.getText("admin.common.words.hide")
      Key Status/Resolution FixVersion
      JAVA-1263 Done 2.12.3, 3.0.0
      CSHARP-987 Done 1.9.2
      PYTHON-705 Done 2.7.2, 3.0
      RUBY-777 Done 1.10.2
      CDRIVER-372 Done
      PHP-1116 Done
      NODE-196 Done 2.0, 1.4.8
      PERL-370 Done 0.704.1.0
      CXX-335 Done legacy-1.0.0-rc1
      $i18n.getText("admin.common.words.show")
      #scriptField, #scriptField *{ border: 1px solid black; } #scriptField{ border-collapse: collapse; } #scriptField td { text-align: center; /* Center-align text in table cells */ } #scriptField td.key { text-align: left; /* Left-align text in the Key column */ } #scriptField a { text-decoration: none; /* Remove underlines from links */ border: none; /* Remove border from links */ } /* Add green background color to cells with FixVersion */ #scriptField td.hasFixVersion { background-color: #00FF00; /* Green color code */ } /* Center-align the first row headers */ #scriptField th { text-align: center; } Key Status/Resolution FixVersion JAVA-1263 Done 2.12.3, 3.0.0 CSHARP-987 Done 1.9.2 PYTHON-705 Done 2.7.2, 3.0 RUBY-777 Done 1.10.2 CDRIVER-372 Done PHP-1116 Done NODE-196 Done 2.0, 1.4.8 PERL-370 Done 0.704.1.0 CXX-335 Done legacy-1.0.0-rc1

      Server versions before 2.6 only return the 'upserted' field in an update result when the upserted _id is an ObjectId. If the user provides any other value for _id in the query spec, or update document (for a replace operation) the upserted field is not returned. This causes invalid counts for nUpserted in the Bulk API result set.

      The purpose of this ticket is to work around the issue in all drivers.

      In all of these examples the server upserts a new document but does not return the _id of the document inserted:

      >>> db.test.count()
      0
      >>> db.test.update({'_id': 0}, {'$set': {'a': 0}}, upsert=True)
      {u'updatedExisting': False, u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 1}
      >>> db.test.find_one({'_id': 0})
      {u'a': 0, u'_id': 0}
      >>> db.test.update({'a': 1}, {'_id': 1}, upsert=True)
      {u'updatedExisting': False, u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 1}
      >>> db.test.find_one({'_id': 1})
      {u'_id': 1}
      >>> db.test.update({'_id': 3}, {'_id': 2}, upsert=True)
      {u'updatedExisting': False, u'connectionId': 1, u'ok': 1.0, u'err': None, u'n': 1}
      >>> db.test.find_one({'_id': 2})
      {u'_id': 2}
      >>> c.server_info()['version']
      u'2.4.10'
      

      There is a code review for the workaround in python here:
      http://codereview.10gen.com/5468598634020864/

            Assignee:
            barrie Barrie Segal
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: