flutter
flutter

Reputation: 6766

Create a collection linked to user ID in Firestore with flutter

Type of App to give context: An app that enables wedding bands to create a profile. Part of this profile will be to enter different dates with locations (Events)and return them in a list view. I have a Firestore collection called userData. The collection is made up of documents IDs(Firebase User ids) generated during sign in. These documents contain fields, mainly Strings and arraysfor things like a header image.I'm thinking of creating a class called Events with member variables date and venue. I'm wondering how I should structure Firestore to allow the Events be queried and returned in a listView. I've looked at sub collections where the UserData would be a parent but I'm not sure is this possible? Or maybe creating a collection at the root called Events but not sure how'd I'd connect the different bands to their Events. Here is a screen shot of Firestore. Each document is a band. enter image description here

Upvotes: 0

Views: 1130

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

You can either:

  1. Use a new top-level collection to store all events, with a field for the id of the band to help with querying for events for only that bad.
  2. Use a subcollection under each band for their events.

It's totally up to you to choose. It will depend on the kinds of queries you want to make. Note that if you go with #2, you will not be able to query for events across bands (at least not until Firestore supports collection group queries which it does not today).

Upvotes: 2

Related Questions