Is MongoDB _id (ObjectId) generated in an ascending order?

前端 未结 3 1718
悲哀的现实
悲哀的现实 2020-12-31 04:11

I know how the _id column contains a representation of timestamp when the document has been inserted into the collection. here is an online utility to convert it to timestam

3条回答
  •  自闭症患者
    2020-12-31 04:24

    For mongo version >= 3.4, the Objectid generation is changed a little. Its structs are:

    • a 4-byte value representing the seconds since the Unix epoch,
    • a 5-byte random value, and
    • a 3-byte counter, starting with a random value.

    So the first 4 bytes are still the seconds since the Unix epoch, it is still almost ascending but not strictly.

    https://docs.mongodb.com/manual/reference/bson-types/#objectid

提交回复
热议问题