I am doing a project for school - android app which registers users to realtime database after it checks if there's a corresponding card number and phone number in a different database in Firestore. At the moment it verifies only the first document, but it wouldn't find the fields if I search for them in other documents.
This is the method I use:
public void checkIfCardExists() { Query query = cardInfo.whereEqualTo("CardNo", cardNumber) .whereEqualTo("Phone", userPhone); query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { boolean documentExists; if (task.isSuccessful()) { Log.d("QueryResult", "Is query result empty: " + task.getResult().isEmpty()); documentExists = !task.getResult().isEmpty(); }else { Log.e("QueryResult", "Error getting documents.", task.getException()); documentExists = false; } if(documentExists) { Log.d("QueryResult", "The document exists"); Toast.makeText(com.example.transportticket.RegistrationLeap.this, "Card number found", Toast.LENGTH_SHORT).show(); userLeap = new UserLeap(userEmail, userPass, userName, userSurname, cardNumber, userPhone); registerUserLeap(userEmail, userPass); startActivity(new Intent(RegistrationLeap.this, Empty.class)); }else{ Log.d("QueryResult", "The document doesn't exist or there was an error retrieving it"); Toast.makeText(com.example.transportticket.RegistrationLeap.this, "Card number not found", Toast.LENGTH_SHORT).show(); startActivity(new Intent(RegistrationLeap.this, Empty.class)); } } }); } And this is how my Firestore database looks like Firestore database