Skip to content

Instantly share code, notes, and snippets.

@alexander-alegre
Created September 21, 2021 21:46
Show Gist options
  • Save alexander-alegre/b3f8b9ca5bc505eb97abcefb9f0ff23d to your computer and use it in GitHub Desktop.
Save alexander-alegre/b3f8b9ca5bc505eb97abcefb9f0ff23d to your computer and use it in GitHub Desktop.
const mongoObjectId = () => {
const timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, () => {
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