Last active
September 18, 2019 20:24
-
-
Save dipaktelangre/cfe5b086cc0bd2b65efb903e84e69d5b to your computer and use it in GitHub Desktop.
MongoDB: Seeding mongodb with test data through JS script and mongo shell
This file contains hidden or 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
| // 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