Skip to content

Commit 11894b5

Browse files
committed
Merge pull request holidayextras#22 from holidayextras/fix-index-creation
Fix index creation
2 parents c233c62 + 142e9f2 commit 11894b5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/mongoHandler.js

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

150-
151150
MongoStore.prototype._createIndexesForRelationships = function(collection, relationshipAttributeNames) {
151+
if (!Array.isArray(relationshipAttributeNames) || !relationshipAttributeNames.length) return;
152+
152153
var index = relationshipAttributeNames.reduce(function(partialIndex, name) {
153-
partialIndex[name + ".id"] = 1;
154+
if (name) {
155+
partialIndex[name + ".id"] = 1;
156+
}
154157
return partialIndex;
155158
}, {});
156-
collection.createIndex(index);
159+
if (Object.keys(index).length) {
160+
collection.createIndex(index);
161+
}
157162
};
158163

159-
160164
MongoStore.prototype._applySort = function(request, cursor) {
161165
if (!request.params.sort) return cursor;
162166

0 commit comments

Comments
 (0)