I'm working on an app with Firestore. I use Firebase Authentication for managing users. The thing is that most of the data in my app would be user-specific. Meaning that users should only have access to their own data.
I've already done research about Firestore security rules, so I know how to handle the security part.
However, I'm wondering how to properly model user-specific data in general. First piece of data I'm adding are categories
, that have (for now) 2 properties: name
and type
.
After some research, I found it's good to create a collection called categories
and then a document per-user, each named after the user's ID (UID).
But then, within such a user-specific document, I want to add my categories. One way I figured it out is like on the screenshot below:
So, to describe this approach in a more generic way:
- New collection for each data type (e.g.
categories
) - Inside the collection, separate document named with UID for each user
- In each user-specific document, a map with an object's data (e.g.
category_1
map with fieldsname = groceries
andtype = expense
However, what worries me here is that I need to somehow invent these names of the maps like category_1
, category_2
etc... I have a feeling something is wrong in this model, but my strong SQL background doesn't allow me to think that through
Do you have any ideas whether this model is a good one or what problems could it produce later? Maybe you can suggest a better approach for modeling user-specific data in Firestore database?