猫鼬模式中的当前日期,带有矩型库

时间:2019-04-15 20:37:24

标签: date mongoose timestamp timezone schema

到目前为止,我已经创建了架构并在该架构中默认了一个时间。但是,这不能按预期工作吗?时间戳设置为我开始表达时的时间,而忽略了文档的实际创建时间。我希望将日期字段表示为字符串,但是中间件似乎不起作用?

let highscoreSchema = new Schema({
    name: { type: String, required: true },
    score: { type: Number, required: true },
    date: { type: String, default: getCurrentTime()}
})

function getCurrentTime(){
    return moment(Date.now()).tz('Europe/Copenhagen').format('DD-MM-YYYY - HH:mm ');

}

如何获取日期,并用在模式中默认创建的字符串表示正确的时区?我应该以某种方式对其进行重组,还是可以直接在架构中实现?

0 个答案:

没有答案