我想檢查輸入的文本 (EditText)元素是否存在使用 Firestore Collection if Exists where exists 或獲取剩余元素注意:我們沒有檔案 ID
如果我們的用戶集合存在移動,我想移動,然后獲取檔案 ID 將使用 AutoID 隨機的剩余元素并忽略其他集合,例如提款請求

我在我的活動中寫了這段代碼
private void fetchDatafromFirestoreCollection() {
firestore.collection("Users").addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
if (error != null) {
if (dialog.isShowing())
dialog.dismiss();
Log.e(TAG, "Error is: ", error);
return;
}
for (DocumentChange documentChange : value.getDocumentChanges())
}
});
}
uj5u.com熱心網友回復:
根據此評論:
我想檢查用戶集合是ReferCode“ABC123”存在如果存在誰是用戶然后我獲取手機或其他詳細資訊
還有這個評論:
我想獲取所有檔案以檢查 ABC123 在哪里存在或不給他推薦金額。
要解決此問題,您必須使用如下所示的查詢:
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference usersRef = db.collection("Users");
usersRef.whereEqualTo("ReferCode", "ABC123").get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
String mobile = document.getString("Mobile");
Log.d("TAG", mobile);
//Do what you need to do with the phone number
}
} else {
Log.d(TAG, "Error getting documents: ", task.getException());
}
}
});
logcat 中的結果將是:
9876543210
uj5u.com熱心網友回復:
使檔案結構像這樣:
DocumentReference docRef = db.collection("Users").document("123456789");
docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() {
@Override
public void onEvent(DocumentSnapshot snap, FirestoreException fe) {
if (snap.exists()) {
//exists
for (DocumentChange dc : snap.getDocumentChanges()) {
//Store exist information to your Object model.
UserInfo userinfo = dc.getDocument().toObject(UserInfo.class);
Log.e(TAG, "userinfo: " userinfo.getCompany);
}
} else {
//not exists
}
}
});
希望它的作業..
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/355630.html
標籤:爪哇 安卓 火力基地 安卓工作室 谷歌云firestore
