我有一種方法可以接收用戶輸入,然后根據選定的過濾器查詢 Cloud Firestore 資料庫。但是要獲得我需要的結果,我必須使用多個“in”運算子執行查詢。有人有解決方法嗎?我的方法:
getGrouped: async function () {
let array = [];
const groupedQuery = query(
collectionGroup(db, "grouped"),
where("owner", "==", match.params.uid),
where("capaign", "in", this.capaign),
where("region", "in", this.region)
);
const groupedSnapshot = await getDocs(groupedQuery);
groupedSnapshot.forEach((doc: any) => {
array.push(doc.data());
});
return array;
},
用戶輸入如下所示: ["CA", "BO", "TX"]
uj5u.com熱心網友回復:
Firestorein每個查詢只允許一個條件。您需要在 JavaScript 中執行第二個處理結果。
getGrouped: async function () {
let array = [];
const groupedQuery = query(
collectionGroup(db, "grouped"),
where("owner", "==", match.params.uid),
where("capaign", "in", this.capaign)
);
const groupedSnapshot = await getDocs(groupedQuery);
groupedSnapshot.forEach((doc: any) => {
if (this.region.includes(doc.get('region'))) {
array.push(doc.data());
}
});
return array;
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/396300.html
標籤:javascript 火力基地 谷歌云firestore
