-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.js
34 lines (28 loc) · 872 Bytes
/
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
/*
* Create a list of available images in MongoDB using a
* files.txt file
*/
const fs = require('fs');
const LineReader = require('readline');
const FILE_LIST = './data/files.txt';
const Main = require('./index.js');
const readImageListToMongo = function (filename) {
const lineReader = LineReader.createInterface({
input: fs.createReadStream(filename)
});
lineReader.on('line', async (line) => {
const [_, tag, imageId] = line.split('/'); // eslint-disable-line
const collection = await Main.getImageCollection();
console.log(collection);
const response = await collection.insertOne({
tag,
imageId
});
console.log(response);
return;
});
return lineReader.on('close', () => {
return Promise.resolve();
});
};
readImageListToMongo(FILE_LIST);