【问题标题】:Firebase firestore unable to read all data (Android)Firebase Firestore 无法读取所有数据(Android)
【发布时间】:2018-10-06 19:12:40
【问题描述】:

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

这是我的数据库:

这是我的代码:

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();
    }
});

【问题讨论】:

标签: android firebase google-cloud-firestore


【解决方案1】:

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

相反,您可以尝试:

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

【讨论】:

  • 那些文档名称是唯一的ID,我希望代码遍历所有文档并找到手机号码的出现(如果有)。
  • 因此,删除document("XSPH...") 并对整个文档进行监听会有所帮助。
猜你喜欢
  • 1970-01-01
  • 2017-10-25
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-30
  • 1970-01-01
相关资源
最近更新 更多