【问题标题】:Updating hashed passwords in Mongoose在 Mongoose 中更新散列密码
【发布时间】:2015-11-18 07:38:06
【问题描述】:

this mongodb blog post 展示了如何存储散列密码。它使用预挂钩,因此在保存密码时会自动对其进行哈希处理。

但是,它还指出钩子不会在“更新”操作时被调用,只是在“保存”时调用。

如何通过 save pre-hook 方法在 Mongoose 中更新密码?

【问题讨论】:

    标签: hash mongoose passwords


    【解决方案1】:

    根据文档,还应该有一个可用的pre update 挂钩。它在这个page 的底部。

    这是更新 updatedAt 字段的代码(根据文档)。

    schema.pre('update', function() {
        this.update({},{ $set: { updatedAt: new Date() } });
    });
    

    【讨论】:

      猜你喜欢
      • 2020-12-20
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 2015-05-24
      • 2021-12-15
      • 2019-05-31
      • 2021-09-27
      • 1970-01-01
      相关资源
      最近更新 更多