-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclear_dups.js
36 lines (33 loc) · 1.5 KB
/
clear_dups.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
module.exports = {
clearDups: () => {
const Firestore = require('@google-cloud/firestore');
const _ = require('lodash');
const firestore = new Firestore({
projectId: ' [projectId] ',
keyFilename: ' [filePath] ',
});
const dupeArray = [];
const collection = firestore.collection('scraped_posts').get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
const data = doc.data();
data.dupeId = doc.id;
dupeArray.push(data);
});
dupeArray.map((val, indexOut) => {
const tempObj = val;
console.log('Original: ', val.title, ' :id: ', val.dupeId);
dupeArray.map((inVal, indexIn) => {
if (val.dupeId !== inVal.dupeId) {
// change title & user.facebook_post_link to any desired field or add more fields...
if (val.title === inVal.title && val.user.facebook_post_link === inVal.user.facebook_post_link) {
firestore.doc('scraped_posts/' + inVal.dupeId).delete().then(() => {
console.log('Found duplicate: ', inVal.title, ' :id: ', inVal.dupeId, ' -DELETED');
});
}
}
})
})
})
}
}