Execute Code after firestore get method is finished

234 views Asked by At

I know that using java (android) you can execute code after the get method is finished, is that also possible when using javascript?

Here is my code:

      mColRef.get().then(function(querySnapshot){
          querySnapshot.forEach(function(doc) {
              console.log(doc.id);
          });
      });

Can I do something like this? Or how would you code something like this for web (javascript)?

     mColRef.get().then(function(querySnapshot){
          querySnapshot.forEach(function(doc) {
              console.log(doc.id);
          });
      }).OnCompleteListener(new OncompleteListener ....

Thanks for your help!

1

There are 1 answers

1
Doug Stevenson On BEST ANSWER

It looks like you're overcomplicating things. The use of then() on a promise in JavaScript serves the same purpose as the use of an OnCompleteListener on a Task object in Android. Just put the code you want to execute after get() completes inside the function you're already passing to then() in your code sample.