matteodelabre / mongoose-beautiful-unique-validation

Plugin for Mongoose that turns duplicate errors into regular Mongoose validation errors
MIT License
117 stars 38 forks source link

findOneAndUpdate is not translated #27

Closed krzysztofpniak closed 8 years ago

krzysztofpniak commented 8 years ago

Does not translate error when save is performed from findOneAndUpdate.

matteodelabre commented 8 years ago

Hello @krzysztofpniak, thanks for the report!

I just published version 5.1.0 which should fix your problem. However, note that the error will not provide the list of fields that made the constraint fail, because the driver does not provide it.

If you need that information, please first find your model, then save it using this kind of code (from Mongoose docs):

Model.findById(id, function (err, doc) {
  if (err) ..
  doc.name = 'jason borne';
  doc.save(callback);
});