确定记录是否为“新的".在预保存回调中 [英] Determine if a record "is new" in the pre save callback
本文介绍了确定记录是否为“新的".在预保存回调中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在猫鼬模型模式的预保存回调中,是否有办法找出记录是否为新"(尚未保存)?
Is there a way to find out if a record "is new" (has not been save yet) in the pre save callback of mongoose model schema?
推荐答案
是的,有一个模型实例上的isNew
布尔属性,用于指示这一点.从预保存中间件以this.isNew
身份访问它.
Yes, there's an isNew
boolean property on a model instance that indicates that. Access it as this.isNew
from your pre save middleware.
这篇关于确定记录是否为“新的".在预保存回调中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文