Query in Firestone where field contains the userID

After implementing the idea that we talked here now I have a student collection in Firestone where there is an array with each field is a combination of the teacherID_subject_academicYear.

Now I would like to be able to query every student where the teacherID is present in the array, but my problem is that the ID is just part of the field.

Maybe it could be solved if I could create a variable where I apply the method slice to the fields in the array and then make the query against the variable. But where could I place that variable? Because in the query box it wouldn’t accept it.

What if you simply save the teacher id into separate field for each student? I dont think Firestore lets you to do query which checks if string contains certain substring.

That’s exactly what I thought just yesterday. Now I am saving with a script the teacherID+subject to query when it is necessary to show both associated, and also just the teacherID in a different array to list all students with that field in the array. It is working fine. I feel as it is a “duplicated” value because the teacher will have the student in two different lists. As their student in a general list (because of the value in the array “teachers”) and as a student for a specific subject (because of the combinated field in the array “subjects”). But it is ok. I don’t think it will be confusing for my collages. I will see.

Thank you!

1 Like

Having lots of repetetive data is quite common when dealing with NoSQL database.

I would say that with Firestore this was the only workable solution.

1 Like