Mongoose provide access to previous value of property in pre('save')
生活随笔
收集整理的這篇文章主要介紹了
Mongoose provide access to previous value of property in pre('save')
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Mongoose allows you to configure custom setters in which you do the comparison. pre(‘save’) by itself won’t give you what you need, but together:
schema.path('name').set(function (newVal) {var originalVal = this.name;if (someThing) {this._customState = true;} }); schema.pre('save', function (next) {if (this._customState) {...}next(); })或者
var Person = new mongoose.Schema({name: {type: String,set: function(name) {this._previousName = this.name;return name;} });Person.pre('save', function (next) {var previousName = this._previousName;if(someCondition) {...}next(); });總結(jié)
以上是生活随笔為你收集整理的Mongoose provide access to previous value of property in pre('save')的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 乌班图 之 常用操作命令(二)
- 下一篇: android Animation 动画