From aac47a1aeec781b29f1f5d2b3178263ad6150ab9 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Mon, 18 Jun 2018 15:16:07 +0200 Subject: [PATCH] fix(db): throw readable error when creating `_id` with background: true --- lib/db.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/db.js b/lib/db.js index 937efcd635..1e59ee3eeb 100644 --- a/lib/db.js +++ b/lib/db.js @@ -1042,6 +1042,7 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) { // 86 = 'IndexKeySpecsConflict' (index already exists with the same name) // 11000 = 'DuplicateKey' (couldn't build unique index because of dupes) // 11600 = 'InterruptedAtShutdown' (interrupted at shutdown) + // 197 = 'InvalidIndexSpecificationOption' (`_id` with `background: true`) // These errors mean that the server recognized `createIndex` as a command // and so we don't need to fallback to an insert. if ( @@ -1049,7 +1050,8 @@ var createIndex = function(self, name, fieldOrSpec, options, callback) { err.code === 11000 || err.code === 85 || err.code === 86 || - err.code === 11600 + err.code === 11600 || + err.code === 197 ) { return handleCallback(callback, err, result); }