根据 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/