Skip to content

Instantly share code, notes, and snippets.

@motaher13
Created April 19, 2021 10:20
Show Gist options
  • Save motaher13/4ec529d8d447397a13b7d2ea80824d5e to your computer and use it in GitHub Desktop.
Save motaher13/4ec529d8d447397a13b7d2ea80824d5e to your computer and use it in GitHub Desktop.
db=db.getSiblingDB("school");
db.person.drop();
var characters = ['a','b','c','d','e','f','g','h','i'];
var charactersLength = 9;
function getRandomInt(n) {
return Math.floor(Math.random() * n);
}
function shuffle() {
var arr = characters; // Convert String to array
var n = charactersLength; // Length of the array
for(var i=0 ; i<n-1 ; ++i) {
var j = getRandomInt(n); // Get random of [0, n-1]
var temp = arr[i]; // Swap arr[i] and arr[j]
arr[i] = arr[j];
arr[j] = temp;
}
s = arr.join(''); // Convert Array to string
return s; // Return shuffled string
}
// 1 million students
for (i = 0; i < 1000000; i++) {
class_id = Math.floor(Math.random()*501); // get a class id between 0 and 500
var contactNo= Math.floor(10000000000 + Math.random() * 90000000000);
var name=shuffle();
var school=shuffle();
var college=shuffle();
var versity=shuffle();
var occupation=shuffle();
var religion=shuffle();
var tag = [shuffle(),shuffle(),shuffle()];
record = {'class_id':class_id,'contactNo':contactNo,'name':name,'school':school,'college':college,'versity':versity,'occupation':occupation,'religion':religion,'tag':tag};
db.person.insert(record);
}
// load("/home/motaher/Desktop/mongo4.js");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment