Skip to content

🐺 This simple module extracts the name of a duplicate field from the Mongoose "duplicate key" error message object.

License

Notifications You must be signed in to change notification settings

bookercodes/mongoose-extract-duplicate-field

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#Mongoose Extract Duplicate Field

This simple module extracts the name of a duplicate field from the Mongoose "duplicate key" error message object.

You can install it using npm:

npm install --save mongoose-extract-duplicate-field

The module exports a function. Once installed, you can import this function:

var extractDuplicateField = require('mongoose-extract-duplicate-field');

And call it, like so:

foo.save(function (error)
  if (error && error.code === 11000) {
    var field = extractDuplicateField(error);

  }
});

The extractDuplicateField function you imported extracts the name of the duplicate field and returns it synchronously. Simple but useful stuff.

About

🐺 This simple module extracts the name of a duplicate field from the Mongoose "duplicate key" error message object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published