forked from meanjs/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Support WiredTiger engine errmsg format in MongoDB 3.2
The new WiredTiger engine is introduced in MongoDB 3.2. It changes the output errmsg format for violation of unique index. This commit adds support for the new format. Fixes meanjs#1245
- Loading branch information
1 parent
a655ad1
commit e964d1f
Showing
2 changed files
with
13 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,17 @@ var getUniqueErrorMessage = function (err) { | |
var output; | ||
|
||
try { | ||
var fieldName = err.errmsg.substring(err.errmsg.lastIndexOf('.$') + 2, err.errmsg.lastIndexOf('_1')); | ||
var begin = 0; | ||
if (err.errmsg.lastIndexOf('.$') !== -1) { | ||
// support mongodb <= 3.0 (default: MMapv1 engine) | ||
// "errmsg" : "E11000 duplicate key error index: mean-dev.users.$email_1 dup key: { : \"[email protected]\" }" | ||
begin = err.errmsg.lastIndexOf('.$') + 2; | ||
} else { | ||
// support mongodb >= 3.2 (default: WiredTiger engine) | ||
// "errmsg" : "E11000 duplicate key error collection: mean-dev.users index: email_1 dup key: { : \"[email protected]\" }" | ||
begin = err.errmsg.lastIndexOf('index: ') + 7; | ||
} | ||
var fieldName = err.errmsg.substring(begin, err.errmsg.lastIndexOf('_1')); | ||
output = fieldName.charAt(0).toUpperCase() + fieldName.slice(1) + ' already exists'; | ||
|
||
} catch (ex) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters