Created
September 13, 2021 16:48
-
-
Save stevelippert/f9fda9ee2e54f60b60de9d7bc81e5d27 to your computer and use it in GitHub Desktop.
A way to generate random birthdays in MongoDB shell.
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
db = db.getSiblingDB("e1_learn-qa"); | |
//db.getCollection("profiles").find({}); | |
var oldest = 24 * 60 * 60 * 1000 * 365 * 18; | |
var newest = 24 * 60 * 60 * 1000 * 365 * 5; | |
var randomDate = function () { | |
return new Date(Date.now() - (Math.random() * (oldest - newest))) | |
} | |
db.profiles.update( | |
{dob: {$exists: false}}, | |
{$set: {"dob": randomDate()}}, | |
false, | |
true | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment