Created
April 30, 2016 03:49
-
-
Save rohitbishnoi/6e6d9556ba0569c18f805a585029f5f8 to your computer and use it in GitHub Desktop.
Script to populate student collection with random records
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 firstNames = ['Alex', 'David', 'Peter', 'Tom', 'Shaun', 'Bill', 'Mary', 'Dan', 'Mark', 'Peter', 'Mikael', 'Sam', 'Tom', 'Fred', 'Robert', 'Martin', 'Peter']; | |
var lastNames = ['Michaels', 'Peterson', 'Jackson', 'Jones', 'Hank', 'Cruise', 'Radcliffe', 'Francis', 'Degroote', 'John', 'Jacobs']; | |
var ageList = [23,24,25,26,27,28,29,30,31,32]; | |
var cities = ["Delhi", "London", "Paris", "Singapore", "Beijing", "Colombo", "Mumbai"]; | |
var examTypes = ["homework", "exam", "quiz"]; | |
var courseType = ["full time", "part time"]; | |
function getRandom(list) { | |
return list[Math.floor(list.length * Math.random())]; | |
} | |
for(i=0; i <= 200000; i++){ | |
var doc = { | |
name : getRandom(firstNames) + " " + getRandom(lastNames), | |
age : getRandom(ageList), | |
city : getRandom(cities), | |
courseType : getRandom(courseType), | |
scores : [ | |
{ | |
"type" : getRandom(examTypes), | |
"score" : Math.floor(100 * Math.random()) | |
}, | |
{ | |
"type" : getRandom(examTypes), | |
"score" : Math.floor(100 * Math.random()) | |
}, | |
{ | |
"type" : getRandom(examTypes), | |
"score" : Math.floor(100 * Math.random()) | |
}, | |
{ | |
"type" : getRandom(examTypes), | |
"score" : Math.floor(100 * Math.random()) | |
} | |
] | |
}; | |
db.student.insert(doc); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment