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

Creating _id index with unique:false should result in error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.4.10, 2.6.1
    • Fix Version/s: 2.7.5
    • Component/s: Index Maintenance
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      // Create a on unique index

      use foo
      db.createCollection("bar",

      {capped: false, autoIndexId: false}

      )
      db.bar.getIndexes()
      // Should return [ ]
      db.bar.ensureIndex({_id:1},

      {unique:false}

      )
      // index on _id will be returned
      db.bar.getIndexes()
      db.bar.insert(

      {"_id" : 1}

      )
      // The insert here will fail
      db.bar.insert(

      {"_id" : 1}

      )
      db.dropDatabase()

      // now the same thing, only the index is not on the id

      use foo
      db.createCollection("bar",

      {capped: false, autoIndexId: false}

      )
      db.bar.ensureIndex(

      {hash:1}

      ,

      {unique:false}

      )
      // index on hash will be returned
      db.bar.getIndexes()
      db.bar.insert(

      {"hash" : 1}

      )
      // The insert here will succeed
      db.bar.insert(

      {"hash" : 1}

      )
      db.dropDatabase()

      // now the same thing without an index

      use foo
      db.createCollection("bar",

      {capped: false, autoIndexId: false}

      )
      db.bar.insert(

      {"_id" : 1}

      )
      // The insert here will succeed
      db.bar.insert(

      {"_id" : 1}

      )
      db.dropDatabase()

      Show
      // Create a on unique index use foo db.createCollection("bar", {capped: false, autoIndexId: false} ) db.bar.getIndexes() // Should return [ ] db.bar.ensureIndex({_id:1}, {unique:false} ) // index on _id will be returned db.bar.getIndexes() db.bar.insert( {"_id" : 1} ) // The insert here will fail db.bar.insert( {"_id" : 1} ) db.dropDatabase() // now the same thing, only the index is not on the id use foo db.createCollection("bar", {capped: false, autoIndexId: false} ) db.bar.ensureIndex( {hash:1} , {unique:false} ) // index on hash will be returned db.bar.getIndexes() db.bar.insert( {"hash" : 1} ) // The insert here will succeed db.bar.insert( {"hash" : 1} ) db.dropDatabase() // now the same thing without an index use foo db.createCollection("bar", {capped: false, autoIndexId: false} ) db.bar.insert( {"_id" : 1} ) // The insert here will succeed db.bar.insert( {"_id" : 1} ) db.dropDatabase()

      Description

      When creating an index on an the _id with unique:false, the uniqueness is still enforced on it.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rassi J Rassi
              Reporter:
              levyavi Avi Levy
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: