Convert Mongo ObjectId to Timestamp and Vice Versa
Online tool for converting ObjectId from timestamp and vice versa
ObjectId in MongoDB is an identifier with following characteristics: small, likely unique, fast to generate, and ordered. It has 12 bytes consisting of (from left to right):
- 4-byte that represents seconds since the Unix epoch,
- 3-byte machine identifier,
- 2-byte process id
- 3-byte counter, starting with a random value.
By default, it's used as the value of _id field of each objects in a collection. The _id field itself is a primary key and is generated automatically if the document to be inserted or updated doesn't have that field.
Usually, the created ObjectId depends on the time it's created. Because it contains bytes that represent time, it's possible to extract timestamp of an ObjectId. This tool allows you to create ObjectId with a specified time and vice versa - extracting timestamp from an ObjectId.