Closed wesleysd1989 closed 6 years ago
in schema not work
const productSchema = new mongoose.Schema({
title: { type: String, required: true, unique: [true, 'Esse produto já esta cadastrado!'] },
description: { type: String, required: true },
numberTickets: { type: Number, min: 1, required: true },
images: [imgSchema],
categories: [categoriesSchema],
tickets: [ticketSchema]
})
@wesleysd1989 http://mongoosejs.com/docs/validation.html#the-unique-option-is-not-a-validator
unique
is not a validator so you can't use custom message there.
What you can do is to manually check for error.name === 'MongoError' && error.code === 11000
and throw a custom error.
hello, i use mongoose on my project
i translated errors on mongoose to pt-br in code i need help to params unique = true, is possible i custon unique msg?
now i recive
i need, exemple: "já existe '{VALUE}' cadastrado"