I have a collection of students and another of teachers. Student documents have the teacher ID inside as a field. I want to save only the teacher's ID to avoid that if the teacher updates his information avoid updating each of the students as i would have to do if you had the teacher document inside the student. When I receive the student's data, is there a way to get the teacher's data in a json? In order to avoid making a new query to the teacher collection looking for the teacher ID, I want to send the teacher's id as a fiels but receive the Teacher object associate with that id
Asked
Active
Viewed 39 times
1 Answers
1
You either duplicate the data in both collections, or you perform two queries. There are no alternatives to this - you need to pick a strategy. There are no SQL-like "joins" in Firestore that allow a query to span multiple collections. With NoSQL databases like Firestore, it's typical to duplicate data (called denormalization) to improve query speed.
See:

Alex Mamo
- 130,605
- 17
- 163
- 193

Doug Stevenson
- 297,357
- 32
- 422
- 441