Query function for distinct result in firestore

时间:2017-12-18 05:52:22

标签: android google-cloud-firestore

Is there any Query function to get the distinct result in firestore.

For example:

Query query = colRef.orderBy("title")
                        .startAt("R")
                        .limit(10);

This gives me all the documents with "title" starting with "R", which contain duplicates like this:

Recording
Running
Running
Running

How can I get a distinct result like this:

Recording
Running

1 个答案:

答案 0 :(得分:0)

Unfortunately there is no ngOnInit() { let T = mergeMap((user: firebase.User) => { return Observable.fromPromise(user.getIdToken()) }); let D = mergeMap((token: string) => {return this.http.get(' https://myfakedomain.com/user?access_token=' + token) }); let P = this.afAuth.authState // return Observable<User> .pipe( T, D ).subscribe(data => this.myData = data); } method within Cloud Firestore. Because you are ordering your data by distinct(), which is a key within each child this is possible. To query your database and get only the distnict elements you need to come up with another solution which would be to create another node named title in which you need to add all those titles. To avoid duplicate elements (overriding data), first you need to check for distinctTitles using exists() method like this:

uniqueness