gpt4 book ai didi

mongodb - MongoDB _id (ObjectId) 是升序生成的吗?

转载 作者:IT老高 更新时间:2023-10-28 13:11:20 25 4
gpt4 key购买 nike

我知道当文档被插入到集合中时 _id 列如何包含时间戳的表示。这是一个在线实用程序,可将其转换为时间戳:http://steveridout.github.io/mongo-object-time/

我想知道的是对象id字符串本身是否保证保持升序?即这种比较是否总是返回真?

“最新对象 id”>“第二个最新对象 id”

最佳答案

不,没有任何保证。来自 official documentation (at the time of the original answer) :

The relationship between the order of ObjectId values and generation time is not strict within a single second. If multiple systems, or multiple processes or threads on a single system generate values, within a single second; ObjectId values do not represent a strict insertion order. Clock skew between clients can also result in non-strict ordering even for values, because client drivers generate ObjectId values, not the mongod process.

latest docs

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, and Are generated by clients, which may have differing system clocks.

关于mongodb - MongoDB _id (ObjectId) 是升序生成的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31057827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com