[SERVER-13518] The _id field is no longer automatically generated by mongos when missing Created: 08/Apr/14  Updated: 11/Jul/16  Resolved: 14/Apr/14

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.6.0
Fix Version/s: 2.6.1, 2.7.0

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Greg Studer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Tested
Operating System: ALL
Backport Completed:
Participants:

 Description   
Issue Status as of April 15, 2014

ISSUE SUMMARY
If the server receives a document for insert that is missing the _id field, it should generate one. A bug in 2.6 caused mongos not to create these _id values. This can violate the assumption that all documents have an _id and can lead to errors when inserting into a collection sharded on _id.

USER IMPACT
Minor, as all drivers automatically generate the _id. Some drivers (for example the Python driver) have an option to disable generating the _id field client-side. Using this option can cause issues when inserting documents to a sharded collection on _id through a mongos.

WORKAROUNDS
Use the driver default to auto-generate _id values.

RESOLUTION
This patch will cause mongos to auto-generate _id values if they are not present.

AFFECTED VERSIONS
Version 2.6.0 is affected by this bug.

PATCHES
The patch is included in the 2.6.1 production release.

Original description

In 2.4 if document to be inserted was missing _id when it got to mongos it seems that mongos would generate the _id.

In 2.6 this does not happen. This breaks in situations where inserted document is going into collection sharded by _id or _id:"hashed".



 Comments   
Comment by Githook User [ 14/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 break child batches up by size or number of documents
(cherry picked from commit 0b1994a25c85324ea413a95ace2470be3efb7db5)

Also includes SERVER-13518 make sure all tested updates are valid with update exprs
(cherry picked from commit 836b1d82810d4b7d98eed8c789f71ed45f473b85)
Branch: v2.6
https://github.com/mongodb/mongo/commit/52da235706ca1713ae91475009348a0ceded5307

Comment by Githook User [ 14/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 break child batches up by size or number of documents
(cherry picked from commit 0b1994a25c85324ea413a95ace2470be3efb7db5)

Also includes SERVER-13518 make sure all tested updates are valid with update exprs
(cherry picked from commit 836b1d82810d4b7d98eed8c789f71ed45f473b85)
Branch: v2.6
https://github.com/mongodb/mongo/commit/52da235706ca1713ae91475009348a0ceded5307

Comment by Githook User [ 14/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 generate _ids in write batches if not set in mongos
(cherry picked from commit 4b589d8aab1675e03dc7efafc32239bda660fe96)
Branch: v2.6
https://github.com/mongodb/mongo/commit/b14b921ba3b3424681212707d82b76097bf13c9d

Comment by Githook User [ 12/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 make sure all tested updates are valid with update exprs
Branch: master
https://github.com/mongodb/mongo/commit/836b1d82810d4b7d98eed8c789f71ed45f473b85

Comment by Githook User [ 11/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 break child batches up by size or number of documents
Branch: master
https://github.com/mongodb/mongo/commit/0b1994a25c85324ea413a95ace2470be3efb7db5

Comment by Githook User [ 11/Apr/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-13518 generate _ids in write batches if not set in mongos
Branch: master
https://github.com/mongodb/mongo/commit/4b589d8aab1675e03dc7efafc32239bda660fe96

Comment by Asya Kamsky [ 08/Apr/14 ]

Discovered using benchRun, tested using Python driver

# against 2.4.x mongos
>>> db.test.insert({"a":1},manipulate=False)
[None]
 
test@mongos(2.4.8) > db.test.find({a:1})
{ "_id" : ObjectId("53446b7c52c9f240d5b65ba2"), "a" : 1 }
 
# against 2.6.0 mongos
db.test.insert({"a":1},manipulate=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.8-intel/egg/pymongo/collection.py", line 357, in insert
  File "build/bdist.macosx-10.8-intel/egg/pymongo/mongo_client.py", line 916, in _send_message
  File "build/bdist.macosx-10.8-intel/egg/pymongo/mongo_client.py", line 859, in __check_response_to_last_error
pymongo.errors.OperationFailure: document { a: 1 } does not contain shard key for pattern { _id: "hashed" }
>>>

Generated at Thu Feb 08 03:32:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.