MongoDB ObjectId ↔ Timestamp Converter
Convert between a MongoDB ObjectId and its embedded creation timestamp, both directions, live as you type.
ObjectId
Time
A MongoDB ObjectId embeds its creation timestamp in the first 4 bytes. The generated ObjectId above is padded with zeros and is not unique. Use it only to compare against real document IDs (e.g. $gt/$lt queries), never to create a new document.
What is MongoDB ObjectId ↔ Timestamp Converter?
Every MongoDB ObjectId embeds its creation time in its first 4 bytes. There's a built-in way to read that timestamp back out inside the Mongo shell (getTimestamp()), but no built-in way to go the other direction: generate an ObjectId from a timestamp you already have. This tool does both, live, in either direction. The most common reason to do this: querying documents by creation date. MongoDB's _id field is indexed by default, so comparing against an ObjectId (db.collection.find({ _id: { $gt: ObjectId("...") } })) is often faster than a separate indexed date field. This tool generates that comparison-ready ObjectId directly, plus the shell-ready query to go with it. One important caveat: the ObjectId generated from a timestamp here is padded with zeros after the timestamp portion, so it is not unique. It's built only for comparison in a query, never to be used as the _id of a real document.
FAQ
No. It's padded with zeros and not unique. Two different timestamps this tool generates could collide with each other or with a real document's ID. It's only safe to use in comparison queries ($gt, $lt, etc.), never as an actual _id.
A real ObjectId has 4 more parts after the timestamp (a random value and a counter) that make it globally unique. This tool can't know those parts. It only reconstructs the timestamp portion, padding the rest with zeros, which is enough for comparison queries but not for identity.
No. It only changes how the date/time is displayed and entered. MongoDB ObjectIds always store an absolute point in time (UTC internally); the toggle just lets you enter or read that time in your local zone instead of doing the conversion yourself.