Skip to content

Instantly share code, notes, and snippets.

Created May 19, 2013 15:40
  • Star 18 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A snippet to convert Mongo ObjectID to javascript timestamps, and vice-versa
----- mongo to js ------
timeStamp = parseInt(Mongo.ObjectId().toString().substr(0,8), 16)*1000
date = new Date(timestamp)
----- js to mongo -----
timestamp = new Date().getTime()/1000
mongoId = new ObjectID(timestamp.toString(16)+1e16)
Copy link

jarandaf commented Apr 4, 2014

Handy! Much appreciated

Copy link

pacuna commented Aug 13, 2014

thanks! that was useful

Copy link

thanks :)

Copy link

Thanks . Really handy

Copy link

z347 commented Jan 5, 2022

Thank you, man :)

Copy link

Thanks man.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment