MongoDB ObjectId ↔ Timestamp Converter

Did you know that each MongoDB ObjectId contains an embedded timestamp of its creation time?

From the mongo shell, you can use getTimestamp() to retrieve the timestamp from the ObjectId, but there's no built in function to generate an ObjectId from a timestamp.

This online converter will convert from timestamp to ObjectId and vice versa.

Other chanty tools

ObjectId


(NOTE: not unique, only use for comparisons, not for creating new documents!)


(convenient to paste into mongo shell)

Time (UTC)

Year (XXXX)
Month (1 - 12)
Date (1 - 31)
Hours
Minutes
Seconds
Milli seconds
Micro seconds
ISO Timestamp

Why generate an ObjectId from a timestamp?

To query documents by creation date.

e.g. to find all comments created after 2013-11-01:

db.comments.find({_id: {$gt: ObjectId("5272e0f00000000000000000")}})