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

ensureIndex should validate its arguments more carefully.

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.9, 2.6.0-rc2
    • Component/s: Shell
    • ALL
    • Hide
      db.test.insert({lname:'David', age:80})
      db.test.insert({lname:'David', age:80})
      db.test.insert({lname:'David', age:80})
      
      db.test.ensureIndex({lname:1,age:1},[unique=true,sparse=true])
      
      db.test.count()
      
      Show
      db.test.insert({lname: 'David' , age:80}) db.test.insert({lname: 'David' , age:80}) db.test.insert({lname: 'David' , age:80}) db.test.ensureIndex({lname:1,age:1},[unique= true ,sparse= true ]) db.test.count()
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Basically, there is parsing of the options in the ensureIndex commands but some edge cases need to be ironed out.

      dropDups get invoked if ensureIndex options are in array syntax [x=true,y=true]

      For example if one inserts

      db.test.insert({lname:'David', age:80})
      db.test.insert({lname:'David', age:80})
      db.test.insert({lname:'David', age:80})
      

      and then issues the command

      db.test.ensureIndex({lname:1,age:1},[unique=true,sparse=true])
      

      This will drop all of their duplicate data as entered above.

      Further, given the parsing of the options as "object" it doesn't matter what 'key' is passed.

      db.test.ensureIndex({lname:1,age:1},[x=true,y=true])
      

      will yield the same results

      However

      db.test.ensureIndex({lname:1,age:1},[x=false,y=true]) 
      

      shall yield a more peculiar result - the dropDups will be stored system.indexes but unique won't be enforced.

      There may be other ways to pass in these options that can be dangerous in similar ways.

            Assignee:
            backlog-server-platform DO NOT USE - Backlog - Platform Team
            Reporter:
            rohit.nijhawan@10gen.com rohit.nijhawan@10gen.com
            Votes:
            1 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: