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

CreateIndexes command accepts index spec with duplicated fields which cause error

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.1.0-rc0
    • Affects Version/s: 5.0.12
    • Component/s: None
    • Query Execution
    • Fully Compatible
    • ALL
    • v8.0, v7.0, v6.0, v5.0
      1. run the golang program
      2. run getIndexes will get the error

      Environment

      mongo-go-driver version: "v1.10.6"

      mongod version: "50.0.12"

      Problem

      When creating indexes through runCommand interface, user can pass a index specification with duplicated fields, which can cause errors when listIndexes etc.

      package main import (
          "go.mongodb.org/mongo-driver/bson"
          "go.mongodb.org/mongo-driver/mongo"
          "go.mongodb.org/mongo-driver/mongo/options"
          "context"
      )func main() {
          ctx := context.TODO()
          var err error
          clientOpt := options.Client().ApplyURI("mongodb://user:password@127.0.0.1:7089")
          client, err := mongo.Connect(ctx, clientOpt)
          if err != nil {
              panic(err)
          }    
            database := client.Database("ycsb")
          res := database.RunCommand(context.Background(), bson.D{
              {"createIndexes", "test"}, 
              {"indexes", bson.A{
                  bson.D{
                      {"v", 2},
                      {"key", bson.D{{"mars", 1},{"moon",1},{"sun",1},{"lastLoginDate",-1}}},
                      {"key", bson.D{{"a",1}}},
                      {"name","mars_1_moon_1_sun_1_lastLoginDate_-1"},
                      {"background",true},
                      {"background",true}}}}})    if res.Err() != nil {
              panic(res.Err())
          }
      }
       

      Running the progrem will cause getIndexes() throw errors

      createIndexes command should check duplidated fields in validate process

            Assignee:
            rui.liu@mongodb.com Rui Liu
            Reporter:
            zhangwenjumlovercl@gmail.com jum zhang
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: