23 พฤศจิกายน 2563

Investigate ObjectId (_id) of MongoDB

ObjectId (_id) of MongoDB is an auto-generated primary key by MongoDB. 


This field consists of 3 parts

1. a 4-byte timestamp value, representing the ObjectId’s creation, measured in seconds since the Unix epoch

2. a 5-byte random value

3. a 3-byte incrementing counter, initialized to a random value


e.g., 5fbb912a5eeb8beee934a5c4

1. timestamp value is 5fbb912a, we can get the creation time by using any computer language to perform basic calculation


2. random value is 5eeb8beee9


3. increasing counter value is 34a5c4

I tried to add more document and get these ObjectIds (_id) consecutively

5fbb91275eeb8beee934a5c0

5fbb91285eeb8beee934a5c1

5fbb91285eeb8beee934a5c2

5fbb91295eeb8beee934a5c3

You can see that the last part of each ObjectId (_id) is increment one by one.

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (All Time)