Skip to content

Commit

Permalink
Fixed ensureIndex so multi key indexes are created in order specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Daniels committed Mar 14, 2014
1 parent b8c5af0 commit e7c7705
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/DBCollection.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
var additionalOps = [];

for( var i = 2; i LTE arrayLen(arguments); i++ ){
arrayAppend(additionalOps, toMongo(arguments[i]) );
arrayAppend(additionalOps, toMongo(arguments[i]) );
}

var output = collection.aggregate( firstOp, additionalOps );
Expand Down Expand Up @@ -435,18 +435,18 @@
*/
public array function ensureIndex(array fields, unique=false, dropDups=false, sparse=false, background=false, name ){
var pos = 1;
var doc = {};
var doc = [];
var options = {};
var indexName = "";
var fieldName = "";

for( pos = 1; pos LTE arrayLen(fields); pos++ ){
if( isSimpleValue(fields[pos]) ){
fieldName = fields[pos];
doc[ fieldName ] = 1;
arrayappend(doc,{"#fieldName#"=1});
} else {
fieldName = structKeyList(fields[pos]);
doc[ fieldName ] = fields[pos][fieldName];
arrayappend(doc,{"#fieldName#"=fields[pos][fieldName]});
}
indexName = listAppend( indexName, fieldName, "_");
}
Expand All @@ -455,7 +455,7 @@
else indexName = arguments.name;

options = { "unique" = unique, "name" = indexName, "dropDups" = dropDups, "sparse" = sparse, "background" = background};
collection.ensureIndex( toMongo( doc ), toMongo( options ) );
collection.ensureIndex( mongoUtil.createOrderedDBObject( doc ), toMongo( options ) );

return getIndexes(collectionName, mongoConfig);
}
Expand Down

0 comments on commit e7c7705

Please sign in to comment.