[英]Saving Dates in MongoDB as 64-bit integers?
I read that MongoDB stores dates natively as a 64 bit integer.我读到 MongoDB 将日期本地存储为 64 位整数。 I just did the following (using mongoose in nodejs):
我只是做了以下(在 nodejs 中使用猫鼬):
MyModel.updateMany({}, { datePublished: new Date("2021-01-01") }).then(
function (result) {
res.json(result);
}
);
And the result looks like this:结果如下所示:
{
...
"datePublished": "2021-01-01T00:00:00.000Z"
}
...doesn't seem to be a 64 bit integer? ...似乎不是一个 64 位整数? Or is this correct, and MongoDB shows me something different here (different to the way it internally stores it)?
或者这是正确的,MongoDB 在这里向我展示了一些不同的东西(不同于它内部存储它的方式)?
From the MongoDB Docs:来自 MongoDB 文档:
BSON Date is a 64-bit integer that represents the number of milliseconds >since the Unix epoch (Jan 1, 1970).
BSON 日期是一个 64 位整数,表示自 Unix 纪元(1970 年 1 月 1 日)以来的毫秒数。 This results in a representable date >range of about 290 million years into the past and future.
这导致过去和未来大约 2.9 亿年的可表示日期 > 范围。
https://docs.mongodb.com/manual/reference/bson-types/#std-label-document-bson-type-date https://docs.mongodb.com/manual/reference/bson-types/#std-label-document-bson-type-date
The dates are stored as an epoch timestamp but is returned as a date object which can be converted into a string if required日期存储为纪元时间戳,但作为日期对象返回,如果需要,可以将其转换为字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.