Skip to content

Commit 9a3ef85

Browse files
committed
Implement "createIndex" via "ensureIndex"
Using arrays instead hash will will make better ordering of indexes "collection.ensureIndex([["firstname", 1], ["lastname", 1]], callback)"
1 parent ea8afe1 commit 9a3ef85

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

lib/mongoHandler.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,20 @@ MongoStore._unknownError = function(err) {
147147
};
148148
};
149149

150-
151150
MongoStore.prototype._createIndexesForRelationships = function(collection, relationshipAttributeNames) {
151+
if (!(relationshipAttributeNames instanceof Array) || !relationshipAttributeNames.length) { return }
152+
152153
var index = relationshipAttributeNames.reduce(function(partialIndex, name) {
153-
partialIndex[name + ".id"] = 1;
154+
if (name) {
155+
partialIndex.push([name + ".id", 1]);
156+
}
157+
154158
return partialIndex;
155-
}, {});
159+
}, []);
156160

157-
if (Object.keys(index).length) {
158-
collection.createIndex(index);
159-
}
161+
collection.ensureIndex(index);
160162
};
161163

162-
163164
MongoStore.prototype._applySort = function(request, cursor) {
164165
if (!request.params.sort) return cursor;
165166

0 commit comments

Comments
 (0)