【问题标题】:Mongoose timestamps - Force specific createdAtMongoose 时间戳 - 强制特定于 createdAt
【发布时间】:2018-03-14 22:55:49
【问题描述】:

我正在使用 mongoose 和 mongoose 时间戳插件,但有时我想添加一个具有特定 createdAt 的对象,而不是现在,有什么方法可以覆盖时间戳?

var timestamps = require('goodeggs-mongoose-timestamps');
var Schema = mongoose.Schema;

var ClientSchema = new Schema({
    name: {
        type: String,
        required: true
    },
    removed: {
        type: Boolean,
        default: false
    },
});

ClientSchema.plugin(timestamps);

module.exports = mongoose.model('Client', ClientSchema);

【问题讨论】:

    标签: mongoose


    【解决方案1】:

    你为什么不在你的架构中放置一个 createdAt 而不是使用插件?而且您可以随时覆盖您的 createdAt。

    createdAt: { type: Date, default: Date.now }
    

    【讨论】:

      猜你喜欢
      • 2016-12-18
      • 2021-12-25
      • 2019-06-24
      • 1970-01-01
      • 2019-09-25
      • 2018-10-08
      • 2019-01-10
      • 1970-01-01
      • 2019-10-14
      相关资源
      最近更新 更多