Firestore查询不成功

时间:2018-07-30 17:21:45

标签: android firebase google-cloud-firestore

firebase guide可以查询如下文档:

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

但是当我尝试实现它时,我的任务并不成功。

这是我的代码

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();
                    }
                }
            });

1 个答案:

答案 0 :(得分:0)

已解决,我们为在Firebase控制台中查询的值创建了一个索引