Skip to content

Instantly share code, notes, and snippets.

@ramyhhh
Created September 24, 2018 17:39
Show Gist options
  • Save ramyhhh/c0cf9b8653b8b2eedb33e9249ccc6829 to your computer and use it in GitHub Desktop.
Save ramyhhh/c0cf9b8653b8b2eedb33e9249ccc6829 to your computer and use it in GitHub Desktop.
Mongo ObjectId generator typescript
class ObjectIdGenerator {
static generate(): string {
let result = Math.round(new Date().getTime() / 1000).toString(16);
for (let i = 0; i < 16; i++) {
result += Math.round(Math.random() * 16).toString(16);
}
return result.substr(0,24);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment