12.6. Firestore Structure for Storing Contacts

At this point, our authentication service is working great. Now have to design our Firestore structure to accommodate a contacts list for each user.

So, we can design the Firestore database with the following structure:

  • Root Document

    • users (collection)

      • user1 (document)

        • contacts (collection)

          • contact1 (document)

          • contact2 (document)

          • contact3 (document)

          • ...

      • user2 (document)

      • user3 (document)

      • ...

We have multiple users, and each user has a list of contacts. Hence, in the above structure:

  1. We have a collection named "users" in our root document, where we store the users (authenticated with FirebaseAuth) as documents.

  2. Each user document will hold a collection named "contacts" to store that user's contact.

  3. In the "contacts" collection, we have all the contact documents.

  4. If you are confused, please revisit the video here: Firestore Data Structure.

When we implement the functionalities in our app, we need to make sure we store and retrieve data following the above Firestore structure.

Last updated