THE MAIN ADVANTAGE OF USING IT IS TO REFER A CERTAIN DOCUMENT TO ANOTHER DOCUMENT .
FOR EXAMPLE:
IF WE HAVE A DOCUMENT ‘FIRST FLOOR’ IN COLLECTION OF FLOORS , THEN ALL ROOM DOCUMENTS WHOSE FLOOR IS FIRST FLOOR SHOULD USE REFERENCE DATA TYPE TO DIRECTLY CONNECT TO THE FIRST FLOOR DOCUMENT.
SO NOW HOW TO ACCESS THIS FIELD ??
JUST LET ME GO THROUGH THE HOME PAGE FIRST , WHERE WE DISPLAY THE PARENT COLLECTION…
THIS IS HOW TO GET THE FLOORS FROM FLOORS COLLECTION.
AND NOW HOW TO GET THE ROOMS WHILE VIEWING THE FLOORS DETAIL PAGE..?
DO READ THE GREEN COMMENTS TO UNDERSTAND THE CODE..!
ON DETAILPAGE WE ARE FIRST GETTING ALL DOCUMENTS WHICH HAVE THEIR REFERENCE SET TO THAT PARTICULAR DOCUMENT BY WRITING
db.collection("rooms").where('floor','==',docRef).get().then(
//GET THOSE DOCUMENTS)
FLOOR FIELD IS THE REFERENCE DATA TYPE AND HAS A REFERNCE OF THE FLOOR DOCUMENT .
IMPORTANT : IT CAN ONLY REFER TO ONE DOCUMENT
NOW HOW TO GET DATA FROM THE REFERENCE FIELD??
VERY EASY !! JUST DO LIKE THIS AND YOU MIGHT GET YOUR DESIRED RESULTS..
JUST A CORRECTION:
room.f=res.data();
//ON LINE 4 OF 'GETTING DATA FROM REFERENCE FIELD' IMAGE
//USE ANY NAME EXCEPT THE NAME ALREADY DEFINED
HOPE THIS HELPS !! 😊😊
IF I AM MISTAKEN FEEL FREE TO CORRECT ME 😅😅