Skip to content

Instantly share code, notes, and snippets.

@rohitbishnoi
Created April 30, 2016 03:49
Show Gist options
  • Save rohitbishnoi/6e6d9556ba0569c18f805a585029f5f8 to your computer and use it in GitHub Desktop.
Save rohitbishnoi/6e6d9556ba0569c18f805a585029f5f8 to your computer and use it in GitHub Desktop.
Script to populate student collection with random records
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