1

I'm after some advice on a Firestore DB structure. I have an app that has a Firestore db and allows a single user (under the one UID) to create a profile for each member of their family (each profile is a document within the collection). In each of the documents, there are the personal details of the family member (as fields. For example, field1 = firstname, field2 = last name, field3 = phone number and so on). This works well but there is one other detail I need to attribute to each and every field within each profile. I need to be able to set a private or public flag against each individual field (for example: firstname has public flag, last name has private flag, Phone number has private flag and so on..). It would be nice if each field could have nested fields underneath (such as a "private" bool field) but that's not how Firestore works. It seems to be Collection/Document/Collection/Document/and so on...

If I didn't need to private/public flag, I would not have an issue. My data would fit perfectly to the Firestore structure.

Does anyone have any suggestions on how I might best achieve this outcome?

Cheers and thanks in advance...

Family Profiles current structure without flags

2 Answers2

1

enter image description here

enter image description here

enter image description here

You can use structure above. With this structure you can fetch private data and public data separately whenever you need. But I have to tell you if you want to show only first name to other users in your app you can use queries on what to show to users. And also always use unique ids to store data rather than hardcoded Names such as JaneDoe or JoeDoe. Otherwise you can face some problems in the future regarding fetching data from firestore.

If you have questions feel free to ask

RamammDev
  • 113
  • 1
  • 7
  • Thanks Rajab, really appreciate the response. I like your concept and would like to use it but I have blown a gasket thinking about how my app will handle it. Like: 1. Each field can be either private or public (set in the app). 2. How does the app know where to pull fields from (private/public) when displaying the profile in the app? I would assume there would be an if statement around each field where if a null is returned (from public) then hit-up the private bucket. – Vincent Bayliss Aug 15 '20 at 00:15
  • As I don't know what kind of app it is I can't answer very clearly. But I think your app uses follow system that when User A can only look at User B's private data if A follows B. If it is true then I recommend you to look at this answer https://stackoverflow.com/questions/46979375/firestore-how-to-structure-a-feed-and-follow-system – RamammDev Aug 15 '20 at 09:46
0

Take a look at the official documentation of Firebase. The information provided there will help you to understand what could be the most suitable solution for work with the data structure on this service. On the other hand for your question, it depends of your use case, will be useful if you could provide us with more context about why would your implementation needs to be as you wanted.

Also, since your concerns are related about how to manage the privacy of your data check this document too.

I hope this information will help you

Harif Velarde
  • 733
  • 5
  • 10