zoukankan      html  css  js  c++  java
  • ObjectId

    BSON Types — MongoDB Manual https://docs.mongodb.com/manual/reference/bson-types/#objectid

    ObjectId

    ObjectIds are small, likely unique, fast to generate, and ordered. ObjectId values consist 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 5-byte random value, and
    • a 3-byte counter, starting with a random value.

    In MongoDB, each document stored in a collection requires a unique _id field that acts as a primary key. If an inserted document omits the _id field, the MongoDB driver automatically generates an ObjectId for the _id field.

    This also applies to documents inserted through update operations with upsert: true.

    MongoDB clients should add an _id field with a unique ObjectId. Using ObjectIds for the _id field provides the following additional benefits:

    • in the mongo shell, you can access the creation time of the ObjectId, using the ObjectId.getTimestamp() method.

    • sorting on an _id field that stores ObjectId values is roughly equivalent to sorting by creation time.

      IMPORTANT

      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.

    SEE ALSO

    ObjectId()

     

     

  • 相关阅读:
    用c写一个小的聊天室程序
    socket相关的开机初始化分析
    HTML——CSS3学习
    iOS--OCR图片识别
    iOS学习——Socket
    iOS学习——数据加密
    iOS学习——并发编程GCD
    iOS学习——weak的应用场景
    iOS学习——RUNLOOP、NSTimer
    iOS学习——锁
  • 原文地址:https://www.cnblogs.com/rsapaper/p/9981981.html
Copyright © 2011-2022 走看看