Skip to content

Instantly share code, notes, and snippets.

@dipaktelangre
Last active September 18, 2019 20:24
Show Gist options
  • Select an option

  • Save dipaktelangre/cfe5b086cc0bd2b65efb903e84e69d5b to your computer and use it in GitHub Desktop.

Select an option

Save dipaktelangre/cfe5b086cc0bd2b65efb903e84e69d5b to your computer and use it in GitHub Desktop.
MongoDB: Seeding mongodb with test data through JS script and mongo shell
// Running the script from CMD
// > mongo db_name mongo-feeder.js
var names = [
"Dipak",
"Sham",
"John",
"Mitika",
"Mathias",
"Anna"
]
var departments = [
"IT",
"FINANCE",
"HR",
"SUPPORT",
"ADMIN"
]
var getRandom = (min, max) => Math.floor(Math.random() * (max - min + 1))
var feed = count => {
while(count > 0){
var emp = {
name : names[getRandom(0, names.length-1)],
department: departments[getRandom(0, departments.length-1)]
};
db.employee.insert(emp)
count--;
}
}
feed(1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment