-
Notifications
You must be signed in to change notification settings - Fork 1
/
pointInTimeRecovery.js
50 lines (45 loc) · 1.54 KB
/
pointInTimeRecovery.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
const throttledQueue = require('throttled-queue');
const {SerializedDocumentArray, SerializedDocument, fromJSON, toJSON, processParsedJoinJSON} = require('@healthtree/firestore-join');
const admin = require('firebase-admin');
admin.initializeApp()
const db = admin.firestore();
const { Timestamp } = require('@google-cloud/firestore');
const fs = require('fs');
const {
difference,
intersection,
sortBy
} = require('lodash')
const {DateTime} = require('luxon');
const {doc} = require('mocha/lib/reporters');
function getRoundedDate(minutes, d=new Date()) {
let ms = 1000 * 60 * minutes; // convert minutes to ms
let roundedDate = new Date(Math.round(d.getTime() / ms) * ms);
return roundedDate
}
async function main(n) {
const query = db.collection('sponsors/')
const date = DateTime.now().minus({minutes: 10}).toJSDate()
const roundedDate = getRoundedDate(1, date)
let readTimestamp = admin.firestore.Timestamp.fromDate(roundedDate)
readTimestamp = admin.firestore.Timestamp.fromDate(
DateTime.fromSeconds(readTimestamp.seconds).toJSDate()
)
console.log(date.toISOString())
console.log(readTimestamp.toDate().toISOString())
const querySnapshot = await db.runTransaction(
(updateFunction) => updateFunction.get(query),
{
readOnly: true,
readTime: readTimestamp
});
const docs = new SerializedDocumentArray(querySnapshot)
for(const doc of docs) {
console.log(doc.ref.path)
await doc.ref.update({
disease: doc.data.disease,
})
}
console.log('done')
}
main().then(_ => console.log('done'));