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

createIndexes command allows duplicate element names in index spec

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.6
    • Affects Version/s: 2.6.10, 3.0.5, 3.1.6
    • Component/s: Index Maintenance
    • Labels:
    • Fully Compatible
    • ALL
    • 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) } }
    • Integrate+Tuning 14 (05/13/16)

      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"
        }
      ]
      

            Assignee:
            vincent.do@mongodb.com Vincent Do
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: