Skip to content

Instantly share code, notes, and snippets.

@skrrp
Forked from solenoid/gist:1372386
Created March 22, 2019 11:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save skrrp/c719e07979b86e5fb96f010c563ac455 to your computer and use it in GitHub Desktop.
Save skrrp/c719e07979b86e5fb96f010c563ac455 to your computer and use it in GitHub Desktop.
javascript ObjectId generator
var mongoObjectId = function () {
var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment