Skip to content

Commit a26fe5f

Browse files
authored
fix(db): don't fall back to insert if 'IndexOptionsConflict' error
re: Automattic/mongoose#4459
1 parent eb85233 commit a26fe5f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/db.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,12 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) {
10461046
createIndexUsingCreateIndexes(self, name, fieldOrSpec, options, function(err, result) {
10471047
if(err == null) return handleCallback(callback, err, result);
10481048

1049-
// 67 = 'CannotCreateIndex', means that the server recognized
1050-
// `createIndex` as a command and so we don't need to fallback to
1051-
// an insert.
1052-
if(err.code === 67 || err.code == 11000) {
1049+
// 67 = 'CannotCreateIndex' (malformed index options)
1050+
// 85 = 'IndexOptionsConflict' (index already exists with different options)
1051+
// 11000 = 'DuplicateKey' (couldn't build unique index because of dupes)
1052+
// These errors mean that the server recognized `createIndex` as a command
1053+
// and so we don't need to fallback to an insert.
1054+
if(err.code === 67 || err.code == 11000 || err.code === 85) {
10531055
return handleCallback(callback, err, result);
10541056
}
10551057

0 commit comments

Comments
 (0)