NestJS,Mongoose - 时间戳返回毫秒而不是秒
NestJS, Mongoose - timestamps returning milliseconds instead of seconds
在模式之上我有以下装饰器
@Schema({
discriminatorKey: 'kind',
timestamps: {
currentTime: () => Math.floor(Date.now() / 1000),
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
},
})
在架构中,我有
@Prop()
CreatedAt: number;
@Prop()
UpdatedAt: number;
每当我更新某些字段时,UpdatedAt
值以毫秒为单位,而不是 timestamps.currentTime
中定义的秒,1638265771286
而不是 1638265771
。我怎样才能解决这个问题?谢谢。
原来我使用的是 bulkWrite
,它不会触发 timestamps
的预挂钩,并且完全忽略了 currentTime
中提供的功能。
它使用一个 ISO 日期对象,然后将该对象转换为 returns 时间戳的数字,以毫秒而不是秒为单位。
在更新密钥中手动将 UpdatedAt
设置为第二似乎不起作用。
在模式之上我有以下装饰器
@Schema({
discriminatorKey: 'kind',
timestamps: {
currentTime: () => Math.floor(Date.now() / 1000),
createdAt: 'CreatedAt',
updatedAt: 'UpdatedAt',
},
})
在架构中,我有
@Prop()
CreatedAt: number;
@Prop()
UpdatedAt: number;
每当我更新某些字段时,UpdatedAt
值以毫秒为单位,而不是 timestamps.currentTime
中定义的秒,1638265771286
而不是 1638265771
。我怎样才能解决这个问题?谢谢。
原来我使用的是 bulkWrite
,它不会触发 timestamps
的预挂钩,并且完全忽略了 currentTime
中提供的功能。
它使用一个 ISO 日期对象,然后将该对象转换为 returns 时间戳的数字,以毫秒而不是秒为单位。
在更新密钥中手动将 UpdatedAt
设置为第二似乎不起作用。