Firebase Firestore无法读取所有数据(Android)

时间:2018-10-06 19:12:41

标签: android firebase google-cloud-firestore

我一直在尝试从Firestore云数据库中读取数据,但无法读取!

这是我的数据库: enter image description here

这是我的代码:

CollectionReference collectionReference = mFirestore.collection("Users");
collectionReference.whereEqualTo("Mobile", mobile.getText().toString()).get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
    @Override
    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
        mobile.setText("");
        Toast.makeText(sign_up_page.this, "Mobile Number Already In Use!", Toast.LENGTH_SHORT).show();
    }
});

1 个答案:

答案 0 :(得分:0)

似乎您是在告诉collectionReference在文档部分.whereEqualTo之后找到Mobile Users

相反,您可以尝试:

DocumentReference docRef = db.collection("Users").document("XSPH..."); // fill with the whole item which starts by `XSPH`
docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
       @Override
       public void onSuccess(DocumentSnapshot documentSnapshot) {

          String mobileItem = documentSnapshot.get("Mobile"); // Declare it as string or integer or whatever you want in here

          Log.d("TAG", documentSnapshot.getString("Mobile")); // or try this
          // Print the mobileItem 

            ...
            ..

看一下: https://firebase.google.com/docs/firestore/query-data/get-data#get_a_document