MongoDB Document Create Date

I recently ran into an issue where I needed to find the date a document was created. I checked out the document in question and found an ObjectID and some fields. I didn’t think there was anyway to recover that information. But, thankfully there is and it’s incredibly easy.

You can just run the node code below from bash or the cmd line. You can either cd to a directory that has the node_module for mongodb or you can just install it globally using:

npm install -g mongodb

Leaving the steps here as a note to myself when I need this info again:

node
var ObjectID = require(‘mongodb’).ObjectID;
var doc = new ObjectID(’54c06f0cb289a8a0748b59a3′);
doc.getTimestamp();