Hello I am fairly new to Firestore and android studio. I am trying to query two different fields within a document so as to fetch that document within a collection in Firestore. In this case the collection name is Dispatch_Records and the documents within the collection contain an auto id. The two fields within the document are driver_identity and extra_driver_identity. The query should fetch a document if the current user Id is equal to that in the field of driver_identity or extra_driver_identity in that document. I noticed that Firestore does not have an OR operator. What can I do so that I can fetch the document required? Below is the code:
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();
}
}
}
}
});