npm install --save @google-cloud/firestore
npm i --save lodash
Same method could be user for firestore or any Array of data.
Examples shows how to remove duplicates in Array - full firestore implementation - HERE
// clear_dups.js
dupeArray.map((val, indexOut) => {
const tempObj = val;
console.log('Original: ', val.title, ' :id: ', val.dupeId);
dupeArray.map((inVal, indexIn) => {
if (val.dupeId !== inVal.dupeId) { // IF YOU WANT TO KEEP ORIGINAL DATABASE ITEM
// this will make sure that one item is left and the rest removed
// change title & user.facebook_post_link to any desired field or add more fields...
if (val.[YOUR-FIELD-VALUE] === inVal.[YOUR-FIELD-VALUE]) {
firestore.doc('scraped_posts/' + inVal.dupeId).delete().then(() => {
console.log('Found duplicate: ', inVal.[YOUR-FIELD-VALUE], ' :id: ', inVal.dupeId);
});
}
}
})
})
node deduper-run
Examples shows how to remove single document by ID or title - full firestore implementation - HERE
You can change title field to any other field you may need to delete by.
// delete_single.js
function deleteById(postID){
if (postID) {
firestore.doc('scraped_posts/' + postID).delete().then(() => {
console.log('Delete post: ', postID, ' :id: ', postID, ' -DELETED');
});
}
}
function deleteByTitle(postTitle) {
if (postTitle) {
firestore.collection('scraped_posts').where('title', '==', postTitle)
.get()
.then(querySnapshot => {
deleteById( querySnapshot.docs[0].id);
})
}
}
// delete by id
node run_delete --id 'id of property'
// delete by title
node run_delete --title 'Title of preperty'