mongodb - mongodb 如何处理 2038 年 1 月 19 日星期二之后的 ObjectId 时间戳?

标签 mongodb timestamp

根据 MongoDB official docs ,它指出:

ObjectId values consists of 12-bytes, where the first four bytes are a timestamp that reflect the ObjectId’s creation, specifically:

  • a 4-byte value representing the seconds since the Unix epoch,
  • a 3-byte machine identifier,
  • a 2-byte process id, and
  • a 3-byte counter, starting with a random value.

我只是想知道 2038 年 1 月 19 日星期二 03:14:08 GMT 当 unix 时间等于 2147483648 时会发生什么适合 ObjectId 中的 4 字节时间戳 *philosoraptor meme*

最佳答案

Unsigned 2,147,483,648 完全适合 4 个字节。 4 个字节足以容纳 4,294,967,295 的值,这是 2106 年 2 月 7 日星期日 06:28:16 GMT 的 unix 纪元。

如果 ObjectID 在此之前保持不变,时间戳部分将从 0 开始,如果您关心的话:

> new Date();
ISODate("2106-02-08T12:41:20.450Z")

> db.t.insert({welcome:"from the future"});
WriteResult({ "nInserted" : 1 })

> db.t.find().pretty();
{
    "_id" : ObjectId("0001a7b306c389186a3a9323"),
    "welcome" : "from the future"
}

> db.t.find()[0]._id.getTimestamp();
ISODate("1970-01-02T06:07:47Z")

关于mongodb - mongodb 如何处理 2038 年 1 月 19 日星期二之后的 ObjectId 时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42097779/

相关文章:

mongodb - 为什么在尝试从mongo集合中获取文档时为什么会出现 “client disconnected”错误?

java - 谁能给我提供 Java 代码来生成 OAuth 请求中使用的时间戳?

mysql - 如何向 MySQL 数据库提交时间戳

MySQL 查询具有最近日期的行

python - 在 python 中过滤日期列表的列表

javascript - 如何根据两个字段的差异对集合进行排序?

MongoDB 使用 pymongo 收集 500K 文档的写入速度很差

java - Spring Data MongoDB 中的上限数组

node.js - MongoDB 按类型和日期分组

mysql - SQL如何按值选择最近的时间戳?