Skip to content

Commit 142e9f2

Browse files
committed
Various robustness fixes.
1 parent 9a3ef85 commit 142e9f2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/mongoHandler.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,17 @@ MongoStore._unknownError = function(err) {
148148
};
149149

150150
MongoStore.prototype._createIndexesForRelationships = function(collection, relationshipAttributeNames) {
151-
if (!(relationshipAttributeNames instanceof Array) || !relationshipAttributeNames.length) { return }
151+
if (!Array.isArray(relationshipAttributeNames) || !relationshipAttributeNames.length) return;
152152

153153
var index = relationshipAttributeNames.reduce(function(partialIndex, name) {
154154
if (name) {
155-
partialIndex.push([name + ".id", 1]);
155+
partialIndex[name + ".id"] = 1;
156156
}
157-
158157
return partialIndex;
159-
}, []);
160-
161-
collection.ensureIndex(index);
158+
}, {});
159+
if (Object.keys(index).length) {
160+
collection.createIndex(index);
161+
}
162162
};
163163

164164
MongoStore.prototype._applySort = function(request, cursor) {

0 commit comments

Comments
 (0)