Osama Tab
Osama Tab

Reputation: 51

Having trouble querying some data from the firestore

I have a Security role in fireStore like this

 allow read: if resource.data.uid == request.auth.uid;

and I am trying to git the data like this

export function GetPatients(limit) {
  return async (dispatch) => {
    await firebase
      .firestore()
      .collection("patients")
      .doc(firebase.auth().currentUser.uid)
      .collection("patient")
      .orderBy("creation", "desc")
      .where("uid", "==", firebase.auth().currentUser.uid && "importent" ,"==" ,true)
      .limit(limit)
      .onSnapshot((result) => {
        let Patients = result.docs.map((doc) => {
          const data = doc.data();
          const id = doc.id;
          return { id, ...data };
        });
        lastPatient = result.docs[result.docs.length - 1];
        dispatch({ type: GET_PATIENTS, Patients });
      });
  };
}

do I need to change the roles or there is something wrong with how a querying the data ?

the error I am getting is

Error in snapshot listener: FirebaseError: Missing or insufficient permissions. –

Upvotes: 0

Views: 37

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600006

This is not how you add multiple conditions to a query:

.where("uid", "==", firebase.auth().currentUser.uid && "importent" ,"==" ,true)

Instead, call where once for each condition. So:

.where("uid", "==", firebase.auth().currentUser.uid)
.where("importent" ,"==" ,true)

Upvotes: 2

Related Questions