官术网_书友最值得收藏!

ObjectId

ObjectId is a special data type for MongoDB. Every document has an _id field from cradle to grave. It is the primary key for each document in a collection and has to be unique. If we omit this field in a create statement, it will be assigned automatically with an ObjectId.

Messing with the ObjectId is not advisable but we can use it (with caution!) for our purposes.

ObjectId is:

  • 12-bytes
  • Ordered; sorting by _id will sort by creation time for each document
  • Storing the creation time that can be accessed by .getTimeStamp() in the shell

The structure of an ObjectId:

  • a 4-byte value representing the seconds since the Unix epoch
  • a 3-byte machine identifier
  • a 2-byte process id
  • a 3-byte counter, starting with a random value

By their structure, ObjectIds will be unique for all purposes; however since these are generated on the client side, one should check the underlying library's source code to verify that implementation is according to specification.

主站蜘蛛池模板: 富平县| 仙桃市| 临猗县| 慈利县| 蕲春县| 电白县| 天祝| 天台县| 房产| 聂拉木县| 中方县| 融水| 抚顺市| 东乡| 惠东县| 罗江县| 抚宁县| 仁化县| 天水市| 顺义区| 曲麻莱县| 成安县| 娱乐| 河源市| 株洲县| 松阳县| 五大连池市| 红原县| 会宁县| 江陵县| 邵东县| 敦煌市| 黄骅市| 乌什县| 惠水县| 东海县| 长春市| 苏尼特右旗| 河曲县| 西吉县| 航空|