【发布时间】:2018-08-05 00:07:42
【问题描述】:
我正在尝试在具有以下结构的单个节点上进行查询:
//object in firestore
fruit = {"Orange","Apple","Pineapple","Banana","Grapes"}
现在我的逻辑是设置我有一个数组,假设我们在数组中有两个像这样的项目
//object in my code
fruit:any = ["Pineapple","Grapes"];
我想检查数组中的项目是否存在于数据库中的fruit下,我执行以下查询
checkFruits(uid,fruit):Observable<any>{
//console.log(fruit);
return this.afs.collection('profiles').doc(uid).collection(`fruit`, ref => ref.
//what to do here to make it check for each item in fruit array ??
where(`fruit.${fruit}`, '==', true)).valueChanges();
}
我不知道如何检查水果对象下数组中每个元素是否存在。
【问题讨论】:
-
任何时候你尝试做
array.exists(item)你应该考虑使用一个类似集合的结构而不是一个数组。见firebase.google.com/docs/firestore/solutions/arrays
标签: typescript firebase google-cloud-firestore angular5 angularfire2