你好,我是Firestore和android studio的新手。我正在尝试查询文档中的两个不同字段,以便在Firestore中的集合中获取该文档。在这种情况下,集合名称为 Dispatch_Records ,并且集合中的文档包含一个自动ID。文档中的两个字段是 driver_identity 和 extra_driver_identity 。如果当前用户ID与该文档中driver_identity 或 extra_driver_identity字段中的用户ID相同,则查询应获取该文档。我注意到Firestore没有OR运算符。我该怎么做才能提取所需的文档?下面是代码:
String user_id = firebaseAuth.getCurrentUser().getUid();
firebaseFirestore.collection("Dispatch_Records").whereEqualTo("driver_identity",user_id)
.whereEqualTo("extra_driver_identity",user_id)
.addSnapshotListener(Deployments.this,new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if(!queryDocumentSnapshots.isEmpty()){
for(DocumentChange doc: queryDocumentSnapshots.getDocumentChanges()){
if(doc.getType() == DocumentChange.Type.ADDED){
String dispatchId = doc.getDocument().getId();
DeploymentsConstructor deployment = doc.getDocument().toObject(DeploymentsConstructor.class).withId(dispatchId);
deploymentsList.add(deployment);
deploymentRecyclerAdapter.notifyDataSetChanged();
}
}
}
}
});