📜  mongoose unique - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:23.080000             🧑  作者: Mango

代码示例3
emailVerificationTokenSchema.post('save', function(error, doc, next) {
  if (error.name === 'MongoError' && error.code === 11000) {
    next(new Error('email must be unique'));
  } else {
    next(error);
  }
});