小编Sim*_*ole的帖子

MongoDB/Mongoose时间戳没有更新

架构:

var schema = new Schema({...}, {
    timestamps: true,
    id: false,
    toJSON: {
        virtuals: true,
    },
    toObject: {
        virtual: true,
    }
});
schema.virtual('updated').get(function () {
    if(typeof this.updatedAt === "undefined" && typeof this.createdAt === "undefined") return "";
    var updated = (typeof this.updatedAt === "undefined") ? this.createdAt : this.updatedAt;
    return "Updated "+moment(updated).fromNow();
});
Run Code Online (Sandbox Code Playgroud)

此代码最近正在运行 - 对于特定实例,updatedAt将在8月24日出现,但对文档的任何新编辑都不会更新时间戳.

感觉我在这里错过了一些非常愚蠢的东西.

mongodb node.js mongoose-schema

9
推荐指数
2
解决办法
5350
查看次数

标签 统计

mongodb ×1

mongoose-schema ×1

node.js ×1