AmitXShukla / Online-School-Management-App-Angular-Firebase

Angular 11.0 Firebase App - Online School , Student Management App
184 stars 88 forks source link

Can you please explain how can i group two collections in firestore based on "id". #6

Closed Narayana-Pathipati closed 4 years ago

Narayana-Pathipati commented 4 years ago

Hi sir, I saw your School Management App with firestore and you done great job. Actually I came from sql background. I am new to firestore I do want to connect two collections based on "Id" and "sub_Id" like joins in sql. Can u please give me a hint to do it in firestore. I am waiting for your valuable reply. Thank u.

AmitXShukla commented 4 years ago

Thanks for reaching out Narayana and I totally get you, coming from SQL background, it's different mind set when working with Document Databases. One of the easiest concept of working with DOCDB like Firebase is, storage is cheaper than network calls. What I mean is, there is no harm to keep all Primary keys and Foreign keys in both the collections, and I would go beyond and repeatedly store all meaningful fields (which I would like to retrieve in one http call) in two collections.

For example, Pretend you have a STUDENT collection which stores Student Id, FNAME, LNAME, Phone # and 20 other fields. There is another collection FEE which store student's fee. In SQL world, I would just store Student ID on FEE table. But in DOCDBs, my FEE collection will have all FEE fields + Student ID, Student FNAME, Student Phone # (whatever Student fields I would want to show while displaying Student Fee report).

You should start building simple collections solution like above example and later improve as you gain deeper understanding of working with document databases.

I hope this helps and makes sense to you.

Narayana-Pathipati commented 4 years ago

Thank you for your valuable reply and spent time for me. In future, if i change the student name and other details in student collection, is there any simple way to update the same student details in fee collection? please clarify me. I am waiting for your reply.