1
我在Mongoose中有一個Article
模型,其中有幾個屬性,其中之一是布爾值approved
。如果正在更改某個屬性,請不要更改updated_at屬性
我也有兩個日期屬性,created_at
和updated_at
。我使用下面的函數處理這兩個:
ArticleSchema.pre('save', function (next) {
'use strict';
var now = new Date();
this.updated_at = now;
if (!this.created_at) {
this.created_at = now;
}
next();
});
使用此代碼,updated_at
即使我只批准物品被改變 - 不過,我使用的是updated_at
屬性顯示一個微小的「編輯」文字,如果updated_at !== created_at
。
如果有任何屬性BUT approved
正在改變,有沒有辦法可以改變updated_at
?
謝謝!