每次保存时,如何在Mongoose模式中使用当前日期更新属性? [英] How do I update a property with the current date in a Mongoose schema on every save?
本文介绍了每次保存时,如何在Mongoose模式中使用当前日期更新属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的数据库集合中,我希望每次使用当前日期时间更新记录时都更新一个"lastChanged"字段.我希望它的格式与猫鼬的默认日期相同,例如:
In my database collections, I want to update a 'lastChanged' field every time the record is updated with the current datetime. I want it to be in the same format as mongoose's default date like:
ISODate("2011-10-06T14: 01: 31.106Z")
有智慧的话吗?
推荐答案
如果只想使用ISO字符串,则:
If you just want an ISO String use:
new Date().toISOString()
这篇关于每次保存时,如何在Mongoose模式中使用当前日期更新属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文