gpt4 book ai didi

node.js - Mongoose 仅​​使用 createdAt 时间戳

转载 作者:IT老高 更新时间:2023-10-28 13:14:27 25 4
gpt4 key购买 nike

我在 Mongoose 中有以下消息架构:

var messageSchema = mongoose.Schema({
userID: { type: ObjectId, required: true, ref: 'User' },
text: { type: String, required: true }
},
{
timestamps: true
});

无论如何都可以忽略 updatedAt 时间戳?消息不会更新,所以更新了会浪费空间

最佳答案

使用 Mongoose v5 可能更好的是执行以下操作;

const schema = new Schema({
// Your schema...
}, {
timestamps: { createdAt: true, updatedAt: false }
})

关于node.js - Mongoose 仅​​使用 createdAt 时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38905633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com