【问题标题】:How to set expires in Mongoose 5.12.5 to expire at 20 days?如何在 Mongoose 5.12.5 中设置过期时间为 20 天?
【发布时间】:2021-07-09 00:40:19
【问题描述】:

我正在尝试在 mongoose 中使用 express 创建 20 天后自动过期,但对我不起作用:“express”:“^4.17.1”、“mongoose”:“^5.12.5”

import { Schema, model } from "mongoose";

const postSchema = new Schema(
  {
    expireAt: { type: Date, default: Date.now, index: { expires: "20d" } },

    title: { type: String, trim: true, default: null },

    imgURL: { type: String, default: null },
  },
  {
    timestamps: true,
    versionkey: false,
  }
);

export default model("Post", postSchema);

¿你能帮帮我吗? 20 天后,mongoose 不会删除我创建的帖子。

如果这个版本的猫鼬不适合这个,请告诉我哪个版本合适

谢谢:)!

【问题讨论】:

    标签: node.js mongodb express mongoose mongoose-schema


    【解决方案1】:

    试试这个:expireAt:{类型:日期,默认:Date.now,过期:'20d'}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-03
      • 2021-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-17
      • 2018-04-29
      • 2017-08-23
      相关资源
      最近更新 更多