'Firestore query on android app is returning empty

Description: I'm making an inventory-keeping app where the number of items you use for your work (or "case") are deducted from the larger number of those items you have in your existing inventory. All data of existing inventory is stored in Firestore under "materials" collection.

Problem: The loop I prepared to access the querySnapshotDocument can't be reached. I was hoping I could get the Material object I need from the loop. But I think I'm missing something.

private void findMaterialInDB(Material material, MaterialDialog dialog) {
    db.collection("materials")
            .whereEqualTo("material", material.getMaterial())
            .whereEqualTo("size", material.getSize())
            .whereEqualTo("description", material.getDescription())
            .limit(1).get()
            .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                @Override
                public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                    Material inventoryMaterial;
                    int inventoryquantity = 0;
                    int casequantity = 0;

                    Log.d("caseQuantityCheck", "Task successful!");
                    for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
                        inventoryMaterial = document.toObject(Material.class);
                        Log.d("caseQuantityCheck", "data: " + document.getData());

                        inventoryquantity = Integer.parseInt(inventoryMaterial.getQuantity());
                        casequantity = Integer.parseInt(material.getQuantity());

                        if (inventoryquantity < casequantity) {
                            Toast.makeText(context, "Not enough materials in Inventory", Toast.LENGTH_LONG).show();
                        } else {
                            //decrease value
                            material.setQuantity("" + (inventoryquantity - casequantity));
                            //TODO: update the firebase value also
                            //proceed to creating case
                            Log.d("caseQuantityCheck", "Material : \n\n" + material);
                            exitingMaterials.add(material);
                            dialog.dismiss();
                            materialCount.setText("Materials (" + exitingMaterials.size() + ")");
                        }
                    }

                }
            });
}

Snapshot of the "materials" collection



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source