mongoose-extract-duplicate-field

1.3.0 • Public • Published

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.0
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.3.0
    1
  • 1.2.0
    0
  • 1.1.0
    1
  • 1.0.0
    1

Package Sidebar

Install

npm i mongoose-extract-duplicate-field

Weekly Downloads

3

Version

1.3.0

License

MIT

Last publish

Collaborators

  • alexbooker