markdown MongoDB中的中间件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown MongoDB中的中间件相关的知识,希望对你有一定的参考价值。

# NEVER FORGET
Custom validators only works on creating a NEW document.
Document Middleware only works before .save() and .create() DO NOT WORK ON UPDATE(


We can add middlewares before and after a certain event.
In case of a document middleware, this event use to be 'save' event.
In the middleware function itself we have access to the 'this' keyword,
which is pointing at the current being save document.

```javascript
tourSchema.pre('save', function(next) {
  this.slug = slugify(this.name, { lower: true });
  next();
});
```

This fucntion only runs before .save() and .create() methods. 
It will not work for for example findByIdAndReplace method.

以上是关于markdown MongoDB中的中间件的主要内容,如果未能解决你的问题,请参考以下文章

markdown [MongoDB] Awesome Cheatsheet #mongodb #cheatsheet

markdown MongoDB查询

markdown MongoDB备忘单

markdown MongoDB的

markdown MongoDB数据源配置

markdown Spring:MongoDB