[SERVER-2403] _genIndexName might create duplicated "_" in a generated index name Created: 24/Jan/11  Updated: 03/Sep/11  Resolved: 03/Sep/11

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 1.6.5
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: pablo platt Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

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;
}



 Comments   
Comment by Eliot Horowitz (Inactive) [ 03/Sep/11 ]

We'll be getting rid of index name soon, so this won't be needed

Generated at Thu Feb 08 02:59:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.