This is my code where I want to get data and to know if data exists or not.
Problem is that if data exists it runs { if(task.isSuccessful() }
but if data doesn't exists, it does nothing!
How can I know that data doesn't exist? I added other { else }
statements but it didn't work.
CollectionReference reference = firestore.collection("Carts").document(FirebaseAuth.getInstance().getCurrentUser().getUid())
.collection("Carts");
reference.whereEqualTo("ordered",false).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
if(document.exists()){
Toast.makeText(ListProducts.this, "Exists", Toast.LENGTH_SHORT).show();
}
else {
// This part is not running even if there is no data
Toast.makeText(ListProducts.this, "NOPE", Toast.LENGTH_SHORT).show();
}
}
}
}
});