有问题,就找官方文档。
地址:https://www.mongodb.com/docs/manual/reference/bson-types/#objectid
While ObjectId values should increase over time, they are not necessarily monotonic.
This is because they:
- Only contain one second of temporal resolution, so ObjectId values created within the same second do not have a guaranteed ordering
- Are generated by clients, which may have differing system clocks.
大意是:
尽管 ObjectId 随着时间递增,但是过程并非单调。主要原因有以下两个:
1、ObjectId 的时间精度只有一秒钟,因此同一秒钟内产生的ObjectId 不能保证单调;
2、不同客户端不同系统计时器导致。
从文档可以得知,当每秒钟内写入某张表数据量较多时,如果根据 _id 排序取值,由于 ObjectId 时间精度的特性无法准确排序,
导致取值丢失。