title: Firestore query with multiple where clauses based on parameters
body: <p>I want to query a Firestore database with multiple where clauses based on the parameters that are passed in. The following block of code works:</p>
  
  <pre><code>getProducts2(accountId: string, manufacturer?: string, materialType?: string): Promise&lt;Product[]&gt; {
    return new Promise&lt;Product[]&gt;((resolve, reject) =&gt; {
      const productCollection2: AngularFirestoreCollection&lt;FreightRule&gt; = this.afs.collection('products');
  
      const query = productCollection2.ref
        .where('materialType', '==', materialType)
        .where('manufacturer', '==', manufacturer);
  
      query.get().then(querySnapshot =&gt; {
        if (querySnapshot.size &gt; 0) {
          const data = querySnapshot.docs.map(documentSnapshot =&gt; {
            return documentSnapshot.data();
          }) as Product[];
          resolve(data);
        } //todo else...
      });
    });
  }
  </code></pre>
  
  <p>But what I really want to do is conditionally include the where clauses based on the optional parameters. The following is what I want, but it doesn't work:</p>
  
  <pre><code>getProducts2(accountId: string, manufacturer?: string, materialType?: string): Promise&lt;Product[]&gt; {
    return new Promise&lt;Product[]&gt;((resolve, reject) =&gt; {
      const productCollection2: AngularFirestoreCollection&lt;FreightRule&gt; = this.afs.collection('products');
  
      const query = productCollection2.ref;
      if (manufacturer) {
        query.where('manufacturer', '==', manufacturer);
      }
      if (materialType) {
        query.where('materialType', '==', materialType);
      }
  
      query.get().then(querySnapshot =&gt; {
        if (querySnapshot.size &gt; 0) {
          const data = querySnapshot.docs.map(documentSnapshot =&gt; {
            return documentSnapshot.data();
          }) as Product[];
          resolve(data);
        } //todo else...
      });
    });
  }
  </code></pre>
  
  <p>While valid, this code just returns all of the products with no filtering. </p>
  
  <p>Is there a way to structure this so I can filter based on the optional parameters?</p>
  
  <p>edit: I realize I can do something like:</p>
  
  <pre><code>let query;
  if (manufacturer &amp;&amp; materialType) {
    query = productCollection2.ref.where(....).where(....)
  } else if (manufacturer) {
    query = productCollection2.ref.where(....)
  } else if (materialType) {
    query = productCollection2.ref.where(....)
  }
  </code></pre>
  
  <p>I was just hoping for something a little more elegant.</p>