-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.cjs
More file actions
40 lines (29 loc) · 1013 Bytes
/
insert.cjs
File metadata and controls
40 lines (29 loc) · 1013 Bytes
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
// backfillPicksCount.cjs
const admin = require("firebase-admin");
const fs = require("fs");
const serviceAccount = JSON.parse(fs.readFileSync("./serviceAccountKey.json"));
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const db = admin.firestore();
async function backfillPicksCount() {
const boardsSnap = await db.collection("boards").get();
for (const boardDoc of boardsSnap.docs) {
const boardId = boardDoc.id;
console.log(`🔍 Checking board: ${boardId}`);
try {
const imagesSnap = await db
.collection("boards")
.doc(boardId)
.collection("images")
.get();
const picksCount = imagesSnap.size;
await boardDoc.ref.update({ picksCount });
console.log(`✅ Board ${boardId} picksCount set to ${picksCount}`);
} catch (err) {
console.error(`❌ Failed to update picksCount for board ${boardId}:`, err.message);
}
}
console.log("🎉 Backfill complete!");
}
backfillPicksCount();