How does Firestore querying work?

Answer

Firestore queries use a query() function with constraint operators: (1) Filter: where("status", "==", "active"), where("price", "<", 100), where("tags", "array-contains", "sale"), where("status", "in", ["active", "pending"]), where("tags", "array-contains-any", ["sale", "clearance"]), where("category", "not-in", ["deleted"]); (2) Order: orderBy("price", "asc") — must include any filtered field in the first orderBy if using range filter; (3) Limit: limit(10), limitToLast(10); (4) Pagination: startAfter(lastDoc), startAt(value), endBefore(value). Full example: const q = query(collection(db, "products"), where("category", "==", "shoes"), where("price", "<", 100), orderBy("price"), limit(20)); const snaps = await getDocs(q). Compound queries require composite indexes — Firestore shows the index creation link in the console error when an index is missing.