Skip to content

Instantly share code, notes, and snippets.

@1mursaleen
Forked from solenoid/gist:1372386
Created October 26, 2021 09:57
Show Gist options
  • Save 1mursaleen/752e685d64bd6836cdfa3d25177d0f74 to your computer and use it in GitHub Desktop.
Save 1mursaleen/752e685d64bd6836cdfa3d25177d0f74 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