【发布时间】:2021-12-28 21:25:17
【问题描述】:
我有一个方法可以接收用户输入,然后根据所选过滤器查询 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"]
【问题讨论】:
-
这是一个记录在案的限制:每个查询最多可以使用一个 in、not-in 或 array-contains-any 子句。您不能在同一个查询中组合这些运算符。
-
还有其他方法可以达到这个效果吗?用户输入是我想用作过滤器的值数组
标签: javascript firebase google-cloud-firestore