6년? 8년? 전에 tokumx mongoDB 부터 사용했었는데,  mongodb java driver 소스를 몇 번 봤었습니다.

(그 당시에는 지금처럼 mongodb가 안정화? 되지 않은 부분도 많았습니다. db커넥션 유지관련 버그 등..)

 

mongodb java driver 소스 중에 인상 깊고, 이후  다른 시스템들의 pk설계할때 많이 참고한 부분이  objectId  부분입니다.(인스타그램의 id체계 참고와 함께)

 

지금도 가끔 필요한 경우 소스를 다시 보는데, 메모 목적으로 내용을 복사해둡니다.(기억력이 예전같지 않아요 ...;)

 


참고 링크:  https://www.mongodb.com/docs/manual/reference/bson-types/

 

ObjectIds are small, likely unique, fast to generate, and ordered. ObjectId values are 12 bytes in length, consisting of:

  • A 4-byte timestamp, representing the ObjectId's creation, measured in seconds since the Unix epoch.
  • A 5-byte random value generated once per process. This random value is unique to the machine and process.
  • A 3-byte incrementing counter, initialized to a random value.

For timestamp and counter values, the most significant bytes appear first in the byte sequence (big-endian). This is unlike other BSON values, where the least significant bytes appear first (little-endian).

If an integer value is used to create an ObjectId, the integer replaces the timestamp.

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.

+ Recent posts