在 Mongoose 中更新散列密码
Updating hashed passwords in Mongoose
this mongodb blog post 展示了如何存储散列密码。它使用预挂钩,因此当密码被保存时,它会自动散列。
但是,它还声明挂钩不会在 'update' 操作上调用,仅在 'save'.
上调用
如何通过 save pre-hook 方法更新 Mongoose 中的密码?
根据文档,还应该有一个 pre update
挂钩可用。它在这个 page.
的底部
这是更新 updatedAt 字段的代码(根据文档)。
schema.pre('update', function() {
this.update({},{ $set: { updatedAt: new Date() } });
});
this mongodb blog post 展示了如何存储散列密码。它使用预挂钩,因此当密码被保存时,它会自动散列。
但是,它还声明挂钩不会在 'update' 操作上调用,仅在 'save'.
上调用如何通过 save pre-hook 方法更新 Mongoose 中的密码?
根据文档,还应该有一个 pre update
挂钩可用。它在这个 page.
这是更新 updatedAt 字段的代码(根据文档)。
schema.pre('update', function() {
this.update({},{ $set: { updatedAt: new Date() } });
});