Anga
Anga

Reputation: 2641

Firestore query not successful

From firebase guide it is okay to query documents like this:

citiesRef.whereEqualTo("state", "CA")
    .whereGreaterThan("population", 1000000);

But my task is not successful when I try to implement it.

This is my code

db.collection("needs")
            .whereEqualTo("topic", topic)
            .whereLessThan("expiresAt", currentTimeStamp)
            //.orderBy("expiresAt",  Query.Direction.DESCENDING)
            //.startAt(ts)
            //.limit(35)
            .get(source)
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    Needs need;
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : task.getResult()) {
                            need = document.toObject(Needs.class).withId(document.getId());
                            needs.add(need);
                            mAdapter.setData(needs);
                        }
                    } else {
                        Toast.makeText(getContext(), "Error getting Data", Toast.LENGTH_SHORT).show();
                    }
                }
            });

Upvotes: 1

Views: 603

Answers (1)

Anga
Anga

Reputation: 2641

It has been solved, we created an Index for the values we are using to query in firebase console

Upvotes: 1

Related Questions