-
Notifications
You must be signed in to change notification settings - Fork 0
/
insertData.js
35 lines (28 loc) · 1.12 KB
/
insertData.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function makeRandomString(length) {
let text = "";
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < length; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
async function insertData(db) {
const TestCollection = db.collection('testcollection');
console.log("Removing all old data first.");
await TestCollection.removeMany({});
const numberOfEntriesToInsert = 200*1000;
console.log(`Starting to insert ${numberOfEntriesToInsert} entries.`);
const tStart = new Date();
for (var i = 0; i < numberOfEntriesToInsert; ++i) {
await TestCollection.insertOne({
field1: makeRandomString(10),
field2: makeRandomString(10),
field3: makeRandomString(10),
field4: makeRandomString(10),
createdAt: new Date(),
createBy: 'insertDataForPerformanceTest'
});
}
const tEnd = new Date();
console.log(`Inserting ${numberOfEntriesToInsert} entries took ${(tEnd-tStart)/1000} [s].`);
}
module.exports = insertData;