这是针对OR
个查询任务
请告诉我如何将其转换为AND
查询?
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference learnings = db.collection("learnings");
Task task1 = learnings.whereLessThan("l_fee", MaximumRequiredPrice)
.get();
Task task2 = learnings.whereLessThan("l_duration", MaximumRequiredDuration)
.get();
Task<List<QuerySnapshot>> allTasks = Tasks.whenAllSuccess(task1, task2);
allTasks.addOnSuccessListener(new OnSuccessListener<List<QuerySnapshot>>() {
@Override
public void onSuccess(List<QuerySnapshot> querySnapshots) {
for (QuerySnapshot queryDocumentSnapshots : querySnapshots) {
for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
Learning learning = documentSnapshot.toObject(Learning.class);
result.add(learning);
adapter.notifyDataSetChanged();
}
}
}
});
答案 0 :(得分:0)
我在这里看到的问题是,当您只需要一个任务并添加了'where'子句时,就有两个任务:
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference learnings = db.collection("learnings");
Task task1 = learnings.whereLessThan("l_fee", MaximumRequiredPrice)
.whereLessThan("l_duration", MaximumRequiredDuration)
.get();