diff --git a/lib/mongodb.js b/lib/mongodb.js index f8a4c4d41..12f908b78 100644 --- a/lib/mongodb.js +++ b/lib/mongodb.js @@ -1870,7 +1870,8 @@ MongoDB.prototype.autoupdate = function(models, cb) { const enableGeoIndexing = this.settings.enableGeoIndexing === true; - async.each( + // Make it serial as multiple models might map to the same collection + async.eachSeries( models, function(modelName, modelCallback) { const indexes = self._models[modelName].settings.indexes || []; @@ -1954,7 +1955,8 @@ MongoDB.prototype.autoupdate = function(models, cb) { debug('create indexes: ', indexList); } - async.each( + // Make it serial as multiple indexes may try to create the same collection at once + async.eachSeries( indexList, function(index, indexCallback) { if (self.debug) {