How can I simultaneously in one “click” event delete two documents from two collection in my cloud firestore?

69
June 13, 2019, at 00:40 AM

i just want to delete multiple documents from two different collections(hive and entry). how should i do this? with two promises or how?

my below code works but the moment I add "location.reload()" anywhere, only the clicked hive is deleted. the page just doesn't work with this refresh function...

please help... thanks in advance!

    deleteBtn.addEventListener('click', (e) => {
      let id = e.target.parentElement.parentElement.getAttribute('data-id');
      var x = confirm("Deleting a hive will delete all its records.  Click 'Ok' to delete and 'Cancel' to return.");
      if(x){
// delete clicked hive
        db.collection('hive').doc(id).delete()
          .then(function () {
          })
          .catch(function (error) {
          })
// delete all entries from within clicked hive
        var deleteEntry = db.collection('entry').where('hive_id', "==", id);
        deleteEntry.get()
          .then(function(querySnapshot) {
            querySnapshot.forEach(function(doc) {
            doc.ref.delete()
            });
          })
          .catch(function (error) {
          })
      }else{
      }
    })

the above approach might be completely wrong and not clean...so i will just type my needed results here...

after clicking deleteBtn and confirming the delete, the clicked hive should be deleted and all entry records from that hive should also be deleted. the page needs to refresh and show that the hive is gone. (note that all entry records have the same hive will have the hives id as property)

THANKS!

READ ALSO
return instruction stop my for-loop in javascript

return instruction stop my for-loop in javascript

when i use a for-loop there is no problem in

102
Webpack External Local Library

Webpack External Local Library

I want to setup my Webpack config (v4+) to exclude an import that is referencing a local libraryIn my app, I import this library like so:

111
Call Back not fired when listening to 'sync' event in service worker

Call Back not fired when listening to 'sync' event in service worker

I am listening to the 'sync' event in my service worker file but NOTHING happensEven my console

96