Created
October 5, 2023 13:33
-
-
Save pedrogardim/1a5559a47b49d0c3b05ae6f858d68285 to your computer and use it in GitHub Desktop.
Golang | Generate random MongoDB ObjectId
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func mongoObjectId() string { | |
ts := time.Now().UnixMilli() / 1000; | |
id := strconv.FormatInt(ts, 16) | |
for i := 0; i < 16; i++ { | |
id += fmt.Sprintf("%x", rand.Intn(16)) | |
} | |
return id | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment