0
votes

So I'm trying to understand how Firebase works. I'm using Firebase cloud for the Database. I have created a collection like this:

'groups': {
     'some_group_name': { ... data ... }
     'other_group_name': { ... data ... }
}

Also each user enters email and password when entered to the app. On the sign up, he chooses the group name. For example in the sign up he will set username, password and some_group_name. But How do I connect between the currently login user and it's group in the database? The only data that Firebase authentication saves is email and password.

Do I need to create another collection users like so?

"users": {
    "some_user_name": "some_group_name"
}

1
Have you used cloud functions ever? I might help you if you use it. That's the easiest solution and safer as you don't need to give your clients write access to Firestore. Though it's possible directly from Android. Can you post Screenshot of database structure. For easier visibility XD. - Dharmaraj

1 Answers

1
votes

You'll need to store the group membership/association of the user somewhere. How to do this, depends on the exact requirements of your app.

If a user can be a member of only one group, you can store their group as a field in a user profile doc. You'd typically have a top-level collection users for this, and a document for each user under that with the user's UID as the document ID (so that you can easily look up the user profile by their UID).

If a user can be a member of multiple groups, you can store that in an array field in the same user profile document. In that case, use arrayUnion and arrayRemove to manipulate the array, so that you can easily query for array membership when needed.