如何从Firestore数据库检索特定数据?

时间:2020-05-02 23:47:57

标签: java android google-cloud-firestore

我正在尝试通过检查条件(该用户的公寓和街区号是否与公寓和街区中的条目匹配,然后检索)来从Firestore数据库中查找具有所有用户详细信息的用户的手机号码他的手机号码。

该图显示了数据库的屏幕快照。 enter image description here

1 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,请尝试以下操作:

 FirebaseFirestore  fireStore = FirebaseFirestore.getInstance();
        final String[] requiredMobile = {""}; //this is up to how you want to use the mobile number acquired
        fireStore.collection("users").get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
            @Override
            public void onSuccess(QuerySnapshot documentSnapshot) {
                for (DocumentSnapshot document: documentSnapshot.getDocuments()
                     ) {
                    if(document.getString("flat")== ("desired Flat") && document.getString("block") =="desired blockNumber"){
                        requiredMobile[0] = document.getString("mobile"); //do something with phone number
                    }

                }
            }
        });