[SERVER-12331] Insert creates the _id field, always Created: 10/Jan/14  Updated: 09/Jul/16  Resolved: 11/Jan/14

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-8237 autoIndexId:false should be disabled Closed
related to SERVER-11611 remove DataFileMgr::insert* Closed
is related to SERVER-12334 Update does not ensure an _id field Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Participants:

 Description   

Not sure how to insert a document with no _id in the shell, so this example uses PyMongo. In 2.4.x, if I create a collection with autoIndexId set to false I can insert a document without an _id field and the _id is not automatically created:

>>> c = pymongo.MongoClient()
>>> db = c.test
>>> coll = db.create_collection("test", capped=True, autoIndexId=False, size=1000)
>>> coll.insert({'a': 'a'}, manipulate=False)
>>> coll.find_one()
{u'a': u'a'}
>>> c.server_info()['version']
u'2.4.8'

In 2.5.5-pre- the _id field is created, regardless of the autoIndexId setting:

>>> c = pymongo.MongoClient()
>>> db = c.test
>>> coll = db.create_collection("test", capped=True, autoIndexId=False, size=1000)
>>> coll.insert({'a': 'a'}, manipulate=False)
>>> coll.find_one()
{u'a': u'a', u'_id': ObjectId('52d0831332e6147c55bbd61b')}
>>> c.server_info()['version']
u'2.5.5-pre-'



 Comments   
Comment by Scott Hernandez (Inactive) [ 11/Jan/14 ]

After SERVER-11611, fixDocumentForInsert unconditionally creates an _id if one doesn't exist for the doc (no longer dependent on if an _id index exists for the collection being inserted into). This means while you can still create a collection without the _id index, the docs will always have an _id field. This is probably not too big a deal since most drivers do this by default and most users aren't concerned with not having an _id field but it is a backwards breaking change.

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