[SERVER-80720] CreateIndexes command accepts index spec with duplicated fields which cause error Created: 05/Sep/23  Updated: 30/Jan/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: 5.0.12
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: jum zhang Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2023-09-05-16-30-12-684.png    
Issue Links:
Duplicate
is duplicated by SERVER-80718 CreateIndexes command accepts index s... Closed
Assigned Teams:
Query Execution
Operating System: ALL
Steps To Reproduce:
  1. run the golang program
  2. run getIndexes will get the error
Participants:

 Description   

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



 Comments   
Comment by Asya Kamsky [ 02/Nov/23 ]

Quick test shows that internal $listCatalog command does not have any issues with the duplicate field, arguing we should be ignoring it everywhere, especially listIndexes

Comment by Alison Rhea Thorne [ 14/Sep/23 ]

Hello,

Thank you for your report!

I've replicated the behavior that you've noted, and have assigned this to an appropriate team to look into. Please watch the ticket for future responses.

Generated at Thu Feb 08 06:44:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.