-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
70 lines (64 loc) · 1.75 KB
/
setup.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
/**
* @description
* DOING: Should import or include the required
* libraries and files for this script to run.
*/
const { MongoClient } = require("mongodb");
const faker = require('faker');
function generateFakeData() {
var i = 0, dataArr = [];
for (i; i < 100; i++) {
dataArr.push({
metaTemplateId: faker.random.uuid(),
status: faker.random.word(),
createdAt: faker.date.past(),
timeZone: faker.address.timeZone(),
language: faker.random.locale(),
signMethod: faker.random.word(),
templatePrice: faker.random.number(),
currency: faker.finance.currencyCode(),
fieldsData: {},
addOns: [
{
id: faker.random.uuid()
},
{
id: faker.random.uuid()
},
{
id: faker.random.uuid()
}
]
});
}
return dataArr;
}
(async function _() {
let database;
try {
const uri = "mongodb://127.0.0.1:27017";
const client = new MongoClient(uri, {
poolSize: 20,
bufferMaxEntries: 0,
useNewUrlParser: true,
useUnifiedTopology: true
});
await client.connect();
database = client.db('_mongo_utils');
database.dropDatabase();
database = client.db('_mongo_utils');
database.createCollection('_test_collection', async function(err, db) {
if (err) {
throw new Error('Could not setup _test_collection');
}
const collection = database.collection('_test_collection');
const data = generateFakeData();
await collection.insertMany(data);
client.close();
});
console.log('\nTest database and collection successfully setup with 100 documents.\n'); // eslint-disable-line
} catch (e) {
throw new Error('Could not setup');
}
})();