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

Insert creates the _id field, always

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Storage
    • None
    • Minor Change
    • ALL

      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-'
      

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: