从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();
}
}
});
答案 0 :(得分:0)
已解决,我们为在Firebase控制台中查询的值创建了一个索引