简体   繁体   English

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

[英]How to retrieve specific data from Firestore Database?

I am trying to find the mobile number of a user from the Firestore database which has all the user details after checking a condition which says if the flat and the block number of the user matches with the entry in flat and block than retrieve his mobile number.我试图从 Firestore 数据库中找到用户的手机号码,该数据库在检查一个条件后包含所有用户详细信息.

The image shows the screenshot of database.该图显示了数据库的屏幕截图。 在此处输入图像描述

If i understand you correctly, try something like this:如果我理解正确,请尝试以下操作:

 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
                    }

                }
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM