【问题标题】:how to remove a field from document after 30 min in mongoose如何在猫鼬中 30 分钟后从文档中删除字段
【发布时间】:2021-10-23 06:41:13
【问题描述】:

我有如下架构,我只想在创建 4 小时后删除令牌日期我尝试了 expire:"4 hour" 但这会删除所有文档:

const driverSchema: Schema = new Schema({
  name: { type: String, required: true },
  lastName: { type: String, required: true },
  email: {
    type: String,
    required: true,
    unique: true,
  },
  phone: {
    type: String,
    required: true,
  },
  creationDate: {
    type: Date,
    required: true,
  },
  password: {
    type: String,
    required: true,
  },
  token: {
    type: String,
  },
});

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    npm 安装 jsonwebtoken

    const jwt = require('jsonwebtoken');
    jwt.sign({
      data: 'foobar'
    }, 'secret', { expiresIn: '0.5h' });  
    

    【讨论】:

    • 感谢您的回答,但我需要从 mongo db 文档中删除令牌,此令牌不是 jwt 令牌
    猜你喜欢
    • 2019-06-06
    • 1970-01-01
    • 2022-11-24
    • 2021-05-16
    • 1970-01-01
    • 2014-08-03
    • 2016-07-30
    • 2021-09-03
    • 2021-07-28
    相关资源
    最近更新 更多