Skip to content

Commit

Permalink
fix: duplication error detection with mongoose 4+ & 5+ (thanks @sp3c1)
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Specjalny <bspecjalny@gmail.com>
  • Loading branch information
sp3c1 authored and nodkz committed Feb 26, 2018
1 parent 38cee73 commit 80b4bb4
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import mongoose, {
type MongooseModel,
} from 'mongoose';

// eslint-disable-next-line import/no-extraneous-dependencies
import { MongoError } from 'mongodb';

export type AutoIncSettings = {|
migrate?: boolean, // If this is to be run on a migration for existing records. Only set this on migration processes.
model: string, // The model to configure the plugin for.
Expand Down Expand Up @@ -58,10 +55,7 @@ export function initialize(): void {
}

function isMongoDuplicateError(e: any): boolean {
return (
(e instanceof MongoError && e.code * 1 === 11000) ||
(e.name === 'MongoError' && e.code * 1 === 11000)
);
return e.code * 1 === 11000;
}

// Initialize plugin by creating counter collection in database.
Expand Down

0 comments on commit 80b4bb4

Please sign in to comment.