我一直在尝试从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();
}
});
答案 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