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

createIndexes command allows duplicate element names in index spec

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.10, 3.0.5, 3.1.6
    • Fix Version/s: 3.3.6
    • Component/s: Indexing
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      Since there is no way to create an arbitrary BSONObj to send to the server from the mongo shell, used the mgo driver to create an index spec with a duplicate element name.

      package main
       
      import (
        "gopkg.in/mgo.v2"
        "log"
      )
       
      func main() {
        session, err := mgo.Dial("127.0.0.1:27017")
        if err != nil {
          log.Fatal(err)
        }
       
        err = session.DB("test").DropDatabase()
        if err != nil {
          log.Fatal(err)
        }
       
        coll := session.DB("test").C("coll")
       
        index := mgo.Index{
          Key: []string{"a", "a", "b"},
        }
        err = coll.EnsureIndex(index)
        if err != nil {
          log.Fatal(err)
        }
      }
      

      Show
      Since there is no way to create an arbitrary BSONObj to send to the server from the mongo shell, used the mgo driver to create an index spec with a duplicate element name. package main   import ( "gopkg.in/mgo.v2" "log" )   func main() { session, err := mgo.Dial("127.0.0.1:27017") if err != nil { log.Fatal(err) }   err = session.DB("test").DropDatabase() if err != nil { log.Fatal(err) }   coll := session.DB("test").C("coll")   index := mgo.Index{ Key: []string{"a", "a", "b"}, } err = coll.EnsureIndex(index) if err != nil { log.Fatal(err) } }
    • Sprint:
      Integrate+Tuning 14 (05/13/16)

      Description

      An index with duplicate element names in the index spec can be created:

      > db.coll.getIndexes()
      [
        {
          "v" : 1,
          "key" : {
            "_id" : 1
          },
          "name" : "_id_",
          "ns" : "test.coll"
        },
        {
          "v" : 1,
          "key" : {
            "a" : 1,
            "a" : 1,
            "b" : 1
          },
          "name" : "a_1_a_1_b_1",
          "ns" : "test.coll"
        }
      ]
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: