Skip to content

Instantly share code, notes, and snippets.

@stevelippert
Created September 13, 2021 16:48
Show Gist options
  • Save stevelippert/f9fda9ee2e54f60b60de9d7bc81e5d27 to your computer and use it in GitHub Desktop.
Save stevelippert/f9fda9ee2e54f60b60de9d7bc81e5d27 to your computer and use it in GitHub Desktop.
A way to generate random birthdays in MongoDB shell.
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