Marvin812
Marvin812

Reputation: 118

Proper way to setup Firestore-database for friendlist-system

Im very new to Android development. At the moment I am trying to develop my first app. My app is going to have a friend-system. Im trying to setup the Firestore-database to match my conditions. I want to use the UserID provided by the google authentication to control the access of the database.

Every user has a friendlist of usernames,since I think, its not safe to let any client know the UserID of another client.

My Firestore database looks like this:

Everytime I want to access data of a user inside my friendlist a have to retrieve data from the users-collection using the UserID-document. Since the client isnt allowed to know the UserID of the friend, I need another collection which I am planing to access through cloud functions to know which userID belongs to the username.

Is there a better way to minimize database-reads while protecting database accesses?

Upvotes: 1

Views: 953

Answers (1)

rsalinas
rsalinas

Reputation: 1547

You could try looking for the UserID(document) based on the Username filed taking the answer from this other thread as a starting point.

Nevertheless, you would need to make sure that the Usernames do not repeat as this may cause issues later on by programming a check in the insertion of updates of usernames.

Otherwise, the solution you are planning would work although with the caveat that you may get a higher billing in the future as you are billed for every read as mentioned here.

Hope you find this useful!

Upvotes: 1

Related Questions