有没有办法动态添加多个条件到Firestore的get请求?
我在那里看到了一些解决方案,但它们在 for/while 循环中包含多个 get() 请求。我需要找到一个基于数组中的数据添加多个过滤器的解决方案。
问题是我有几个具有多个选择值的过滤器,但我不确定用户会选择其中的多少个。
citiesDb
.where('city', '==', 'New York')
.where('city', '==', 'Paris')
.where('city', '==', 'London')
// It can be multiple more based on let cities = [] (with size of 0 to many)
// There can be also a few more arrays with filters
.get()
最佳答案
这对你有用吗?
let query = citiesDb;
for (const city of cities) {
query = query.where("city", "==", city);
}
query.get().then(...) // result
关于javascript - 使用循环向 Firestore 的 get() 添加多个条件,一般 javascript 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57545759/