[DRIVERS-151] Handle Bulk API edge case for pre-2.6 servers when upserted _id not returned Created: 17/May/14  Updated: 15/Apr/19  Resolved: 04/Oct/16

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Barrie Segal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on CXX-335 Ensure we handle Bulk API edge case (... Closed
depends on CDRIVER-372 Handle Bulk API edge case for pre-2.6... Closed
depends on CSHARP-987 Handle Bulk API edge case for pre-2.6... Closed
depends on NODE-196 Handle Bulk API edge case for pre-2.6... Closed
depends on PYTHON-705 Handle Bulk API edge case for pre-2.6... Closed
depends on RUBY-777 Handle Bulk API edge case for pre-2.6... Closed
depends on JAVA-1263 Handle Bulk API edge case for pre-2.6... Closed
Related
related to SERVER-13865 Shell returns incorrect WriteResult f... Closed
Tested
Driver Compliance:
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

 Description   

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/



 Comments   
Comment by Andrew Morrow (Inactive) [ 03/Mar/15 ]

Validating for C++11 because validated for C

Generated at Thu Feb 08 08:20:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.