-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 1009 Bytes
/
index.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
const Promise = require('bluebird');
const runPerformanceTest = require('./runPerformanceTest');
const insertData = require('./insertData');
const [,, version, actions] = process.argv;
if (!version) {
console.error('version is required');
return;
}
if (!actions) {
console.error('actions are required');
return;
}
const URL = process.env.MONGO_URL;
const DB_NAME = 'perf_test';
console.log(URL);
console.log(DB_NAME);
const mongodb = require(`mongodb${version}`);
Promise.promisifyAll(mongodb);
async function getClient(mongodb) {
return await mongodb.MongoClient.connect(URL, {useNewUrlParser: true, useUnifiedTopology: true});
}
async function start() {
const client = await getClient(mongodb);
try {
const db = client.db(DB_NAME);
actions.includes('i') && await insertData(db);
actions.includes('r') && await runPerformanceTest(db);
client.close();
}
catch (e) {
console.log(e);
client.close();
}
}
start();