1

I have documents where I have a map field of teacher containing uid and username and in that same document I have a array field of students that contains the student id's now I want to query documents based on both field how can I merge the code below

var teacherRef = db.collection('classes')
                   .where("teacher.id", "==", localStorage.getItem("user"))

var studentRef = db.collection('classes')
                   .where("students", "array-contains", localStorage.getItem("user"))
2
  • I want to create a logical OR operation with this two where queries Commented May 31, 2020 at 16:06
  • I found this Medium article that might be helpful to you on this concept. Commented Jun 3, 2020 at 9:31

1 Answer 1

1

You can combine multiple where in a single query :

var classTeacherRef = db.collection('classes')
    .where("teacher.id", "==", localStorage.getItem("user"))
    .where("students", "array-contains", localStorage.getItem("user");

Keep in mind that Firebase will ask you to create index for both properties to make it work.

Sign up to request clarification or add additional context in comments.

1 Comment

This will not solve my problem because it is a logical AND operation with two queries but I want to create a logical OR operation between this two where query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.