Firebase Firestore - OR query alternative

后端 未结 2 500
陌清茗
陌清茗 2020-12-18 09:38

In this question Firebase Firestore - OR query they said there is no OR query. This means I can\'t easily query for items that have an ID that is in an array I got earlier.

2条回答
  •  被撕碎了的回忆
    2020-12-18 10:11

    You could combine the Observables using rxjs;

    orQuery(){
    
        const $one = this.afs.collection("items", ref => ref.where("itemId","==","1")).valueChanges();
        const $two = this.afs.collection("items", ref => ref.where("itemId","==","3")).valueChanges();
    
        return combineLatest($one,$two).pipe(
            map(([one, two]) => [...one, ...two])
        )
    }
    
    getOr(){
        this.orQuery().subscribe(data => console.log(data))
    }
    

提交回复
热议问题