- What is it? A DocumentReference is a Firestore object that points to a specific document in a collection, like /users/abc123. It’s used to link related documents instead of duplicating data, keeping things consistent and storage-efficient.
- How it’s created? We use the doc() function from firebase/firestore, e.g., doc(db, ‘collectionName’, ‘documentId’).
- Why use it? It enables relational data modeling, making it easy to reference documents (e.g., a user or menu item) and fetch their data when needed.
- In our project: In MenuPage.tsx, we create DocumentReference for fields like foodType, mealType, menuItem, and createdBy to link documents in menuItems and dailyMenus collections.
This approach keeps our Firestore data organized and scalable. Let me know if you have tips or questions about using DocumentReference!