简体   繁体   English

猫鼬模型禁用删除

[英]mongoose model disable remove

i want disable remove docs in some doc model. 我想在某些doc模型中禁用删除文档。 Inside doc pre hook I can do somthing like that: 在doc pre hook中,我可以做这样的事情:

someSchema.pre('remove', function (next) {
  let err = new Error('Delete docs is not allowed!');
  next(err);
});

But remove still can be executed by someModel.remove() How I can avoid this? 但是删除仍然可以通过someModel执行。删除()如何避免这种情况?

answer was simple: just override remove fun like this: 答案很简单:只需覆盖删除这样的乐趣:

let model = mongoose.model('doc', someDocSchema);
model.remove = function () {
  throw new Error('Delete docs is not allowed!');
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM