You can easily configure and display error messages for unique: true validation errors using mongoose-beautiful-unique-validation .
To do this, simply use the mongoose-beautiful-unique-validation package:
npm install
Then you can simply use it as a global plugin (as shown below) or for each circuit.
const beautifyUnique = require('mongoose-beautiful-unique-validation'); mongoose.plugin(beautifyUnique);
See this comment and Readme on GitHub for full details and help.
You can also use the mongoose-validation-error-transform package to display Mongoose validation error messages.
source share