[英]Is it possible to query firebase-firestore data by multiple criteria/values
是否可以使用可選的多個條件查詢 firestore? 假設我想過濾來自 firebase firestore 集合的數據,如果用戶提供來自多個輸入字段的可選輸入(例如:工作類型、薪資范圍、位置、發布日期等...)
要根據多個條件構建查詢:
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.