_genIndexName might create duplicated "_" in a generated index name

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.6.5
    • Component/s: Shell
    • None
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      DBCollection.prototype._genIndexName generates index name automatically if it is not supplied.
      It concatenates keys and direction. For example,

      {field1: 1, field2: -1, field3: 1}

      results with field1_1_field2_-1_field3_1
      If instead of direction with have a string (2d) we might have duplicate "" or unneeded "" at the end.
      Example 1:

      {field1: 1, field2: "2d"}

      "field1_1_field2_"

      Example2:

      {field1: 1, field2: "2d", field3: -1}

      "field1_1_field2_field3-1"

      It's not a big deal but other drivers might implement it in a different way
      and the duplicated "_" might cause a confusion.

      https://github.com/mongodb/mongo/blob/master/shell/collection.js#L218

      Fix:
      DBCollection.prototype._genIndexName = function( keys ){
      var name = "";
      for ( var k in keys )

      { var v = keys[k]; if ( typeof v == "function" ) continue; if ( name.length > 0 ) name += "_"; //name += k + "_"; // ------------- if ( typeof v == "number" ) //name += v; // --------------- name += "_" + v; // +++++++++ }

      return name;
      }

            Assignee:
            Unassigned
            Reporter:
            pablo platt
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: