Reputation: 81
I am trying to figure out the best way to structure the data for my app. I want it so users have a list of trips and then can go to a detail view for expenses (fuel, hotel, food, misc).
The number of trips for a user will be a lot and this is just an example there will be about 20 items on the details page. I feel like I am overthinking it but not sure if having it read all 20 items of every trip in the list just to display 2 items for each trip is a good idea.
Not sure if it will make a difference but I am using Xcode 12.4
Would it be best to have the trip summary and then a subcollection of details?
users:
- UID: "randomly_generated"
- firstName: "James"
- email: "[email protected]"
trips:
- startDate: "2/5/2022"
- destination: "Orlando, FL"
- userID: "Users UID"
- details: []
- food: "150"
- hotel: "400"
- fuel: "250"
- misc: "75"
or should I just have it all under trips?
users:
- UID: "randomly_generated"
- firstName: "James"
- email: "[email protected]"
trips:
- startDate: "2/5/2022"
- destination: "Orlando, FL"
- userID: "Users UID"
- food: "150"
- hotel: "400"
- fuel: "250"
- misc: "75"
Upvotes: 0
Views: 208
Reputation: 323
Try this:
users:
trips:
/// add this next part if you wish to do less queries or if you ever use rtdb
///
When querying with Firestore you can make direct composite queries in the trips child and specify the UID you want and it will retrieve all of them, additionally, you can limit the amount of trips you want to return
https://firebase.google.com/docs/firestore/query-data/queries
With RTDB, you cannot make multiple filter queries at the same time hence why you would need to add a separate userTrips child in order to filter out all the trips to a specific user
https://firebase.google.com/docs/database/ios/read-and-write
Upvotes: 1