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

Unique Index on a single text field has unexpected behavior with spaces

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Works as Designed
    • Affects Version/s: 3.6.4
    • Fix Version/s: None
    • Component/s: Text Search
    • Labels:
      None
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Used the mongo shell on powershell.

      > use test
      switched to db test
      > db.testCol.createIndex( { "name": "text" } , { unique: true } );
      {
       "createdCollectionAutomatically" : true,
       "numIndexesBefore" : 1,
       "numIndexesAfter" : 2,
       "ok" : 1
      }
      > db.testCol.insert( {"name": "test co"} )
      WriteResult( { "nInserted" : 1 })
      > db.testCol.insert( {"name": "test2 co"})
      WriteResult({
       "nInserted" : 0,
       "writeError" : {
       "code" : 11000,
       "errmsg" : "E11000 duplicate key error collection: test.testCol index: name_text dup key: { : \"co\", : 0.75 }"
       }
      })
      

      Show
      Used the mongo shell on powershell. > use test switched to db test > db.testCol.createIndex( { "name": "text" } , { unique: true } ); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.testCol.insert( {"name": "test co"} ) WriteResult( { "nInserted" : 1 }) > db.testCol.insert( {"name": "test2 co"}) WriteResult({ "nInserted" : 0, "writeError" : { "code" : 11000, "errmsg" : "E11000 duplicate key error collection: test.testCol index: name_text dup key: { : \"co\", : 0.75 }" } })

      Description

      Applying a unique index to a single text field has unexpected behavior with spaces.

      OS: Windows 10

      For example:

      Inserting "test co" and "test2 co" fail uniqueness.

      Inserting " co" and "       co" fail uniqueness.

       

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: