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

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

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.6.4
    • Component/s: Text Search
    • None
    • Server Triage
    • ALL
    • 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 }" } })

      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.

       

            Assignee:
            backlog-server-triage [HELP ONLY] Backlog - Triage Team
            Reporter:
            Matherz831 Mathew Cabutage [X]
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: