Mangodb批量造数据js脚本
faker.locale = "en"
const STEPCOUNT = 1000; //total 1000 * 10000 = 10000000 1000万数据量生成
function isRandomBlank(blankWeight) {
return Math.random() * 100 <= blankWeight;
};
for (let i = 0; i < 10000; i++) {
db.getCollection("code_items").insertMany(
_.times(STEPCOUNT, () => {
return {
"forced": false,
"process": "Auto",
"code": faker.phone.phoneNumberFormat(),
"createdBy": {
"companyId": "1125df74-914f-49a5-94b9-5d5c808b1f02",
"companyName": "特斯拉(上海)有限公司",
"name": "特斯拉管理员",
"id": "643bb37d-8910-419c-b61f-25349cfee4f5"
},
"line": "1",
"workstation": "AOI",
"inputTime": faker.date.between('2021-03-17','2021-03-19'),
"inputType": "online",
"source": "center",
"combination": {
"parents": [],
"children": []
},
"companyName": "特斯拉(上海)有限公司",
"companyId": "1125df74-914f-49a5-94b9-5d5c808b1f02",
"operator": "特斯拉管理员",
"createdAt": ISODate("2021-02-03T15:18:54.939+08:00"),
"updatedAt": ISODate("2021-02-03T15:18:54.939+08:00")
}
})
)
console.log("code_center:code_items", `${(i + 1) * STEPCOUNT} docs inserted`);
}