-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdateTime.js
51 lines (39 loc) · 1.43 KB
/
updateTime.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
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
var os = require('os');
// Connection URL
let mongoUrl = 'mongodb://rss-webtoons:27017';
let dbName = 'rss-webtoons';
let feedLocation = "/feed/"
if(os.platform() == "win32"){
mongoUrl = 'mongodb://localhost:27017';
dbName = 'testProject';
feedLocation = "c:\\tmp\\"
}
async function GenerateFeed(){
let client, db;
try{
client = await MongoClient.connect(mongoUrl, {useNewUrlParser: true});
db = client.db(dbName);
async function UpdateTimes(collection){
var posts = await collection.find().toArray()
let n = 0
for(let post of posts){
n+=1
await collection.updateOne({ _id: post._id }, { $set: { insertTime: Date.parse(post.modTimeGmt) } })
console.log(n)
}
}
const comics = db.collection("comics");
var allComics = await comics.find().toArray()
for(let comic of allComics){
const seriesTitleNo = comic.seriesNum
const collection = db.collection(seriesTitleNo);
// const episodes = db.collection(seriesTitleNo + '_episodes');
await UpdateTimes(collection)
}
}
catch(err){ console.error(err); } // catch any mongo error here
finally{ client.close(); } // make sure to close your connection after
}
GenerateFeed()