Is it possible to query firestore with optional multiple criteria? Let's say I want to filter the data from firebase firestore collection if the user provides optional input from multiple input fields (example: Job Type, Salary range, location, date posted, etc... )
To build a query out of multiple conditions:
let query = firebase.firestore().collection("your collection");
if (jobType) {
query = query.where("jobType", "==", jobType);
}
if (salaryRangeMin && salaryRangeMax) {
query = query.where("salary", ">=", salaryRangeMin)
.where("salary", "<=", salaryRangeax);
}
if (location) {
query = query.where("location", "==", location);
}
const snapshot = await query.get();