title: Angular 6 and Firestore: best way to loop through and update each Document in AFS Collection?
body: <p>This is an Angular 6 and Firestore project. I am trying to iterate through and update each document in my <code>articlesCollection</code>. A click event triggers the method that does the loop. The problem is, sometimes the method loops through the collection only once. Other times it loops infinitely. Is there a problem with my method? Is there a better way to loop through and update each doc in a collection?</p>
  
  <p>Edit: When I hard reload localhost:4200, the first time I trigger the method it loops through once. If I trigger the method a second time, it loops infinitely. </p>
  
  <pre><code>featureArticle(article) {
      const articleArray = this.articlesCollection.snapshotChanges();
  
      articleArray.subscribe( payload =&gt; {
        payload.forEach( item =&gt; {
          const ID = article.id;
          const articleID = item.payload.doc.data().id;
          const articleTITLE = item.payload.doc.data().title;
          const articleToUpdate = this.articlesCollection.doc(`${articleID}`);
          if (ID === articleID) {
            articleToUpdate.update({
              isFeature: true
            });
          } else {
            articleToUpdate.update({
              isFeature: false
            });
          }
          alert(`${articleTITLE} updated`); &lt;-- LOOPS INFINITELY
        });
    });
  }
  </code></pre>
  
  <p>The template:</p>
  
  <pre><code>&lt;ng-container *ngFor="let article of articles | async"&gt;          
    &lt;div (click)="featureArticle(article)"&gt;
       {{ article.title }} 
    &lt;/div&gt;   
  &lt;/ng-container&gt;
  </code></pre>