Last active
November 20, 2015 08:38
-
-
Save darkcolonist/c47aad7c6cb162e435e0 to your computer and use it in GitHub Desktop.
nodejs insert random people in db
This file contains 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
var mongojs = require("mongojs"), | |
db = mongojs('test', ['people']) | |
var names1 = [ "Matthew","Carlos","Cornelia","Alan","Samuel","Jeanette","Joel","Polly","Mathilda","Larry","Jane","Lucy","Gavin","Mable","Bertie","Mark","Travis","Dorothy","Stanley","Phoebe","Arthur","Sadie","Mark","Lewis","Alex","Callie","Winnie","Elijah","Johnny","Adelaide","Jayden","Clara","Barbara","Laura","Francis","Harvey","Marc","Nannie","Joseph","Nellie","Frank","Julian","Belle","Amelia","Elizabeth","Caleb","Jessie","Derek","Grace","Nathaniel","Christian","Nellie","Elsie","Maurice","Jared","Cecelia","Martha","Eula","Jean","Ricardo","Mittie","Luis","May","Landon","Jennie","Eula","Belle","Ivan","Hallie","Robert","Eleanor","Sarah","Lou","Olivia","Christina","Wayne","Larry","Celia","Herman","Charlotte","Barry","Martin","Frances","Raymond","Ricky","Cody","Rena","Garrett","Janie","Lenora","Emilie","Iva","Edward","Evelyn","Lydia","Terry","Betty","Lydia","Nathaniel","Myra" ] | |
var names2 = [ "Evan","Gregory","Alvin","Albert","Derek","Amanda","Gregory","Tom","Jayden","Lelia","Steve","Alberta","Roger","Edna","Alta","Jessie","Gordon","Ella","Lettie","Marcus","Francis","Daisy","Verna","Danny","Duane","Myra","Agnes","Florence","Linnie","Leonard","Nora","Frederick","Rena","Carrie","Harvey","Sallie","Margaret","Violet","Frank","Ina","Samuel","Clyde","Peter","Leona","Rosie","Frances","Fanny","Agnes","Violet","Zachary","Daisy","Hallie","Jeffrey","Philip","Brent","Jerome","Ina","Lawrence","Lola","Lewis","Mario","Rosa","Emma","Helen","Zachary","Nell","Barbara","Gavin","Louise","Harold","Emma","Delia","Wesley","Brian","Lola","Sue","Travis","Glenn","Kenneth","Minerva","Randall","Richard","Lawrence","Bryan","Ryan","Essie","Erik","Jeanette","Clarence","Catherine","Marguerite","Cora","Rosa","Theodore","Pearl","Madge","Julia","Maude","Louise","Etta" ] | |
var names3 = [ "Sadie","Ada","Violet","Hunter","Craig","Bernard","Ricardo","Harry","Mable","Kathryn","Jim","Lydia","Ophelia","Duane","Lucy","Stanley","Emilie","Robert","Lola","Amelia","Adeline","Dorothy","John","Don","Jorge","Garrett","Nannie","Maud","Hester","Frederick","Julian","Michael","Justin","Martha","Millie","Jeffrey","Etta","Mark","Jesse","Philip","Lee","Floyd","Gerald","Evan","Nathaniel","Florence","Gene","Nora","Lilly","George","Harriet","Barry","Pauline","Alfred","Ethan","Eliza","Blanche","Logan","Dale","Laura","Jackson","Sallie","Nathan","Donald","Rosetta","Landon","Dominic","Duane","Leo","Leo","Steve","Cora","Lawrence","Abbie","Franklin","Carlos","Tony","Carl","Anthony","Harvey","Alberta","Jeffery","Francisco","Christian","Leila","Amy","Catherine","Lawrence","Virginia","Elizabeth","Bernard","Celia","Ryan","Jeremy","Rosalie","Sallie","Virgie","Barry","Carolyn","Luella" ] | |
var names4 = [ "Kelley","McCormick","Hughes","Flowers","Cannon","Salazar","Marsh","Harris","Waters","Cole","Dixon","Wade","Benson","Lamb","Daniel","Howard","Vasquez","Webb","Lindsey","Bryan","Hawkins","Rodgers","Collins","Love","Fleming","Hernandez","Patrick","Bryan","Marsh","Goodwin","Sherman","Gordon","Price","Sims","Santiago","Roberson","Klein","Griffith","Stevens","Simon","Parks","Wolfe","Miles","Reeves","Wilkins","Ray","Hernandez","Long","Burke","Weber","Moran","Wallace","Morris","Jimenez","Robbins","Grant","Valdez","Griffin","Francis","McLaughlin","Terry","Ball","Newman","Floyd","Thomas","Cunningham","Watkins","Patrick","Hopkins","Bradley","Blair","Swanson","Parsons","Holt","James","Miller","Massey","Singleton","Robertson","Davidson","Ballard","McLaughlin","Luna","Moore","McGuire","Hopkins","Black","Alexander","Rogers","Carlson","Fisher","Phillips","Garner","Atkins","Palmer","Newton","Joseph","King","Schneider","Martinez" ] | |
// var person = db.people.find().limit(1, function(err, docs){ | |
// docs.forEach(function(item){ | |
// console.log(item.name) | |
// }) | |
// console.log("done!") | |
// process.exit() | |
// }) | |
/** | |
* You first need to create a formatting function to pad numbers to two digits… | |
**/ | |
function twoDigits(d) { | |
if(0 <= d && d < 10) return "0" + d.toString() | |
if(-10 < d && d < 0) return "-0" + (-1*d).toString() | |
return d.toString() | |
} | |
/** | |
* …and then create the method to output the date string as desired. | |
* Some people hate using prototypes this way, but if you are going | |
* to apply this to more than one Date object, having it as a prototype | |
* makes sense. | |
**/ | |
Date.prototype.toMysqlFormat = function() { | |
return this.getUTCFullYear() + "-" + twoDigits(1 + this.getUTCMonth()) + "-" + twoDigits(this.getUTCDate()) + " " + twoDigits(this.getUTCHours()) + ":" + twoDigits(this.getUTCMinutes()) + ":" + twoDigits(this.getUTCSeconds()) | |
} | |
db.people.runCommand('count', function(err,res){ | |
insertRandom(res.n) | |
}) | |
// insertRandom(1) | |
var current = db.people.find({}, function(err, docs){ | |
console.log(docs.count()) | |
}) | |
function insertRandom(totalSoFar){ | |
var strategy = Math.floor(Math.random()*3); | |
if(strategy == 0){ | |
// console.log("strategy 1"); | |
var name1 = names1[Math.floor(Math.random()*100)] | |
var name2 = names2[Math.floor(Math.random()*100)] | |
var name3 = names3[Math.floor(Math.random()*100)] | |
}else if (strategy == 1){ | |
// console.log("strategy 2"); | |
var name3 = names1[Math.floor(Math.random()*100)] | |
var name1 = names2[Math.floor(Math.random()*100)] | |
var name2 = names3[Math.floor(Math.random()*100)] | |
}else if (strategy == 2){ | |
// console.log("strategy 3"); | |
var name2 = names1[Math.floor(Math.random()*100)] | |
var name3 = names2[Math.floor(Math.random()*100)] | |
var name1 = names3[Math.floor(Math.random()*100)] | |
} | |
var name4 = names4[Math.floor(Math.random()*100)] | |
var randno1 = Math.floor(Math.random()*1000) | |
var randno2 = Math.floor(Math.random()*1000) | |
var fullname = name1 + " " + name2 + randno1 + " " + name3 + randno2 + " " + name4 | |
var datenow = new Date().toMysqlFormat() | |
// console.log(fullname); | |
var toinsert = { | |
name: fullname, | |
date_created: datenow | |
} | |
db.people.insert( toinsert , function(err, doc){ | |
totalSoFar++ | |
console.log(totalSoFar +": "+fullname) | |
// setTimeout(function(){ | |
// insertRandom(totalSoFar) | |
// }, 1) | |
insertRandom(totalSoFar) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment