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

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.

主站蜘蛛池模板: 宁陵县| 韶关市| 福州市| 化隆| 托克托县| 绥中县| 苏尼特左旗| 扶风县| 锦屏县| 清远市| 丹东市| 拜城县| 土默特左旗| 万荣县| 石门县| 乌拉特中旗| 陇南市| 吉水县| 五峰| 阳谷县| 麻栗坡县| 南京市| 老河口市| 苏尼特右旗| 周口市| 铁岭县| 平阴县| 井研县| 吴忠市| 铁力市| 丰县| 来凤县| 望谟县| 宣汉县| 清远市| 蓬莱市| 临澧县| 平昌县| 洪湖市| 磐安县| 黑水县|