FeathersJS Mongoose:PUT 使 "createdAt" 和 "updatedAt" 消失

FeathersJS Mongoose: PUT makes "createdAt" and "updatedAt" disappear

我有一个具有以下猫鼬模式的服务(我还没有附加任何挂钩):

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const restaurantSchema = new Schema({
  text: { type: String, required: true }
}, { timestamps: true });

const restaurantModel = mongoose.model('restaurant', restaurantSchema);

module.exports = restaurantModel;

问题是:每当我发送 PUT 请求时,createdAtupdatedAt 都会从我的对象中消失。

不应该 timestamps: true 让 mongoose 保留时间戳并更新 updatedAt 的值吗?

作为 Daff , that is just the expected behavior for PUT. Reading the repo, I found that what causes this behavior is the overwrite option. It is set to true by default,导致更新完全替换当前对象,不留下任何时间戳。

我真的应该使用 PATCH 只更新某些字段并保留时间戳。