Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个上传Schema文件,其中存储了上传文件的日期,例如:
Schema
uploaded_date: { type: Date, default: Date.now(), }
通过这样保存日期,猫鼬将文件的日期和时间完全一样地存储。例如:
uploaded_date: 2020-05-19T08:10:00.034+00:00
当我在一分钟左右上传多个文件时。为什么会出现这种情况?我应该timestamp用于区分时间吗?
timestamp
使用Date.now而不是 Date.now()
Mongoose 在创建新记录时会将 Date.now 替换为当前日期时间,因此它将为每条记录更新。但是,如果您使用 Date.now() 您的默认值将设置为固定时间(架构的创建时间)。
uploaded_date: { type: Date, default: Date.now, }