Firestore: Multiple Conditional where Clauses

When querying data in Firestore, you might want to use multiple conditional where clauses to filter your data based on specific conditions.

Firestore supports multiple where clauses with “equality” (==) operators or using array-contains, array-contains-any, and in operators.

To use multiple equality filters, you can chain multiple where clauses like this:

import { getFirestore, collection, query, where, getDocs } 
       from "firebase/firestore";

const db = getFirestore();
const myCollection = collection(db, "myCollection");

const q = query(
  where("field1", "==", "value1"),
  where("field2", "==", "value2"),
  where("field3", "==", "value3")

const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
  console.log(, "=>",;

The collection() returns a CollectionReference, extending Query, and the objects are immutable when you use methods like where() and orderBy(); they return new Query objects with additional operations.

To build your query with multiple where and orderBy operations, you can chain these calls together and assign the resulting Query object to a variable, which you can then use to execute the query.

However, if you need to use multiple range filters on different fields, you must do client-side filtering or restructure your data to accommodate this limitation.

For example, you could create a composite field that combines the values of the fields you want to filter on and then use a single range filter on that composite field. However, remember that this might not be the most efficient solution and could require more complex data management.

If you need more advanced querying capabilities, you might want to consider using a different database solution, such as Google Cloud Firestore’s sibling service, Google Cloud Datastore, or another NoSQL database with more advanced querying options.

That’s it.

Leave a Comment