forked from GhMartingit/xk6-mongo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-insertbatch.js
42 lines (31 loc) · 939 Bytes
/
test-insertbatch.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
36
37
38
39
40
41
42
import xk6_mongo from 'k6/x/mongo';
const client = xk6_mongo.newClient('mongodb://localhost:27017');
const batchsize = 50;
export default () => {
let docobjs = []
for (let i = 0; i < batchsize; i++) {
docobjs.push(getRecord());
}
client.insertMany("test", "test", docobjs);
}
function getRecord() {
return {
_id: `${makeId(15)}`,
correlationId: `test--couchbase`,
title: 'Perf test experiment',
url: 'example.com',
locale: 'en',
time: `${new Date(Date.now()).toISOString()}`
};
}
function makeId(length) {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
counter += 1;
}
return result;
}