2017-12-18 134 views
0

是否有任何查询函数在firestore中获取不同的结果?针对不同结果的查询函数在firestore中

例如:

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

这给了我所有以“标题”开始与“R”包含重复这样的文件,:

Recording 
Running 
Running 
Running 

我怎样才能得到一个不同的结果像这样:

Recording 
Running 
+0

的可能的复制https://stackoverflow.com/questions/35170616/firebase-and-select-distinct – R2R

回答

0

不幸的是,在云中没有distinct()方法公司的FireStore。因为您正在通过title订购您的数据,这是每个孩子的关键,这是可能的。要查询数据库并只获取distnict元素,您需要提出另一个解决方案,该解决方案将创建另一个名为distinctTitles的节点,您需要在其中添加所有这些标题。为了避免重复的元素(覆盖数据),首先你需要使用exists()法这样的检查uniqueness

DocumentReference docRef = db.collection("distinctTitles").document("titleToCheck"); 
docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { 
    @Override 
    public void onComplete(@NonNull Task<DocumentSnapshot> task) { 
     if (task.exists()) { 
      //Do something 
     } else { 
      //Do something else 
     } 
    } 
}); 
相关问题